Tuesday, November 25, 2008

Setting the Style for div via C#.NET

Had to look this up again so documenting for quick reference. It's rather simple to set a div style using the following steps:

Step 1; The div must have a unique id and be configured with runat="server":
 <div id="myDivId" runat="server" class="head2"> 

Step 2; The code behind references the div as if it were any other Control on the page, using the Controls Style property to set a style attribute:
 myDivId.Style["background-color"] = "#ffdd77";