Reputation: 9
I'm new in ASP.NET and i have a little problem . I have a master page which has a div and i want to edit the height of this div dynamically with code. I don't want to change the href to another css file , i just want to edit this css file.
<div id="div" runat="server" ></div>
#div
{
position:absolute;
background-color:red;
width:200px;
height:150px;
}
I tried this , but doesn't work :
System.Web.UI.HtmlControls.HtmlGenericControl div;
div.Style.Add("height","200px");
Upvotes: 0
Views: 46
Reputation: 125
Although Scottys answer is correct, a nicer way might be the following:
div.Attributes.CssStyle.Add("height", "200px");
This will allow you to change individual css attributes.
Upvotes: 0
Reputation: 1137
This should do the trick...
If you're writing this code in the code-beind of the master page you can just write the following:
div.Attributes.Add("style", "position:absolute;background-color:red;height:200px;height:150px;");
Otherwise, if you're on a content page, you'd add this before the code above...
var div = (System.Web.UI.HtmlControls.HtmlGenericControl) Page.Master.FindControl("div");
Upvotes: 1