How do you modify a CSS style in the code behind file for divs in ASP.NET?

EverTheLearner picture EverTheLearner · Mar 18, 2009 · Viewed 308.8k times · Source

I'm trying to modify a CSS style attribute for a div based on the information I get from a database table in the code behind of my aspx page. The following is essentially what I am trying to do, but I get errors.

Aspx:

<div id="testSpace" runat="server">
    Test
</div>

Code Behind:

testSpace.Style = "display:none;"    
testSpace.Style("display") = "none";

What am I doing wrong?

Answer

Andy White picture Andy White · Mar 18, 2009
testSpace.Style.Add("display", "none");