|
How to apply CSS style in the Label control from code-behind?
by: Itfunda
Product Type: Tips and Tricks (Books)
Technologies: ASP.NET
This how to describes you how to apply CSS style in the Label control from code-behind.
ASPX PAGE< p><asp:Label ID="Label3" runat="server" Text="My third Label"></asp:Label></p>
CODE BEHINDprotected void Page_Load(object sender, EventArgs e){ // writeing text from code behindLabel2.Text = "Written from code behind";// Applying CSS style from code behindLabel3.Text = "Written from code behind";Label3.Font.Bold = true;string[] fontNames = {"Verdana", "Arial"};Label3.Font.Names = fontNames; Label3.Font.Size = FontUnit.Larger; Label3.ForeColor = System.Drawing.Color.Green; Label3.BackColor = System.Drawing.Color.Yellow; }
CSS style can be applied from code behind by accessing the properties of the control with the help of its Id. Most of the CSS styles can be applied using the Font property and its sub properties of the Label control. However you can use ForeColor and BackColor directly from the Label control.
Demo Path: /Label-Literal/LabelPage.aspx
|