Archive

Posts Tagged ‘style.add’

Changing Css Class or Style At Run time dynamically in Asp

August 21, 2009 Leave a comment

You can add/change css style or add new attributes to current style at runtime, in asp.net code behind.

Lets say you have:

<a ID=”linktemp” style=”text-decoration:underline” class=”verdana12bluebold” runat=”server” >Download</a>

Now if we want to change its class dynamically then in code behind we have to do:

linktemp.Attributes.Add(“class”, “verdana13greynormalitalic”);

if we want to change its text-decoration under style then,

linktemp.Style.Add(“text-decoration”, “none”);

in the similar you can add new styles, change visible option to true/false,

linktemp.Style.Add(“display”, “block”);