Altering CSS at runtime using C#.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under ASP.NET category on | Points: 40 | Views : 196
Below sample code shows how to alter the CSS at runtime,I have placed the label inside div and added runat
attribute.In page load,I have assigned the CSS name to div.
<div>
<asp:Button ID = "Button1" runat = "server" OnClick = "Button1_Click" Text = "Button" />
<div id = "divName" runat = "server">
<asp:Label ID = "Label1" runat = "server" Text = "Name: "></asp:Label>
</div>
</div>

.lblStyle
{
text-decoration:none;
font-weight: bold;
font-size:12px;
color:#007ddd;
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
divName.Attributes["class"] = "lblStyle";
}
}

Comments or Responses

Login to post response