Saturday, June 7, 2014

Change the CSS class of div made into a web forms control in C#.

<div id="Whatever" runat="server" class="displaynone">
   The quick red fox jumps over the lazy brown dog.
</div>

 
 

What is above may be manipulated like so.

private void Tweak(int foo)
{
   if (foo > 0)
   {
      Whatever.Attributes["class"] = "";
   } else {
      Whatever.Attributes["class"] = "displaynone";
   }
}

 
 

See also my trick for manipulating styles here.

No comments:

Post a Comment