Home > Asp.net > Changing Css Class or Style At Run time dynamically in Asp

Changing Css Class or Style At Run time dynamically in Asp


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”);

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: