I am converting an old script from ASP to ASP.NET and would like some advice. The original ASP script used Response.Write to output information about what happened during execution. I have rewritten the entire thing in ASP.NET but it is new to me as an old-school C programmer. The job requirements include using the VB flavor of ASP.NET, btw.
I originally put up a TextBox and edited the text property to dump my final report. Now they want different colors for different message importance and I find that the TextBox can only do one color for all lines. I fell back to the old standby R.W but I get a message that it’s not declared and from looking around I see that it’s an issue because I’m calling it from the code behind and that is ‘out of scope’ from the HTML elements of the page itself.
My question is what is the best way to output information to the web page with different lines being different colors from a page’s code-behind?
Secondary question – if I have misunderstood anything feel free to correct my thinking. 🙂
Thanks!
Literal is the correct approach in my opinion too, to prevent messiness you can wrap it nicely with some functions.
First, have one literal control that will be the messages placeholder:
Second, use CSS for the colors it’s more elegant and flexible.. for example:
Now have this function:
And finally to add message have such code anywhere in your code:
You can make it even more elegant by using
enumfor message type and more, but the above is enough for basic needs. 🙂By having each message in its own
<div>you make it be in its own line automatically and you can control each message easier with CSS.Edit: my code is C# but can be converted easily to VB.NET as well.