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;
}
Supply it HTML as,
string showmsg = "<span style='color:red'> Please Answer Question </span>";
That will be rendered as multiple spans. It's better if you use other controls which support color change from the C# code. Like Label
and use its property Label.ForeColor
If you don't want to change in Code Behind, do same thing in Design. But, here span
is outside Literal
tag:
<span style="color:red"><asp:Literal ID="litmessage" runat="server"></asp:Literal></span>
It works too and no need to upload bin
files again, if your application is LIVE!
I would change it to a Label. At that point, you have the option of using CSS and the .CssClass property, or just straight ASP.NET using the ForeColor property.
You can use Label control instead which has ForeColor property that you can set
<asp:Label ID="lblMessage" ForeColor="Gren" runat="server" ></asp:Label>
In code behind
lblMessage.ForeColor = System.Drawing.Color.Green;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With