- 11 months ago 109
ASP.NET (C#) Question

how to display literal control in specific color

// I have a survey style page that I want to setup controls in case a question is not answered I have attached the following code to a Literal. I would like to know if I can change the color of the text inside the literal to Red.

if (RadioButtonList1.SelectedItem == null)
string showmsg = "Please Answer Question";
Literal1.Text = showmsg;

Answer Source

Supply it HTML

string showmsg = "<span style='color:red'> Please Answer Question </span>";

That will be rendered as multiple spans. Its better if you use other controls which supports colour change from the C# code. Like Label and use its property Label.ForeColor