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

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


testSpace.Style.Add("display", "none");


It's an HtmlGenericControl so not sure what the recommended way to do this is, so you could also do:

testSpace.Attributes.Add("style", "text-align: center;");

or

testSpace.Attributes.Add("class", "centerIt");

or

testSpace.Attributes["style"] = "text-align: center;";

or

testSpace.Attributes["class"] = "centerIt";


Another way to do it:

testSpace.Style.Add("display", "none");

or

testSpace.Style["background-image"] = "url(images/foo.png)";

in vb.net you can do it this way:

testSpace.Style.Item("display") = "none"