Let's add background color and width to a Label control at runtime.
(Runtime means on button click event or something like that).
Label1.Attributes.CssStyle.Add("background-color", "#007700");
Label1.Attributes.CssStyle.Add("width", "320px");
May 19, 2010
Change CSS of a ASP.NET control at runtime. (C#)
Labels:
ASP.NET,
background color,
c#,
change css at runtime,
CSS,
css at runtime,
label control,
runtime,
width
Subscribe to:
Post Comments (Atom)
We can only change the CSS of a control at runtime if it is a ASP.NET Sever Control, having id and the runat="Server"
ReplyDeleteWe can do this using follwoing method also.
Label1.Style("width") = "320px"
This method will be good in case the control has already "width" property assigned with some different value. It is also good if the control don't have that property set at all.