Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display literal control in specific color

Tags:

c#

asp.net

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;
   }
like image 257
Lui.net Avatar asked Aug 30 '13 19:08

Lui.net


4 Answers

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

like image 174
Habib Avatar answered Sep 20 '22 20:09

Habib


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!

like image 31
Vikrant Avatar answered Sep 21 '22 20:09

Vikrant


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.

like image 39
Garrison Neely Avatar answered Sep 20 '22 20:09

Garrison Neely


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;
like image 23
Hammad Khan Avatar answered Sep 18 '22 20:09

Hammad Khan