I need to change the height of a div container(CSS Property Height) from ASP.NET code (VB).
How can I do that?
Thanks
I need to change the height of a div container(CSS Property Height) from ASP.NET code (VB).
How can I do that?
Thanks
C#, because I don't want to typo the VB syntax.
Markup:
<div runat="server" id="divControl">...</div>
Class of the Page:
protected System.Web.UI.HtmlControls.HtmlGenericControl divControl;
OnLoad/Other function:
divControl.Styles.Add("height", number / anotherNumer);
As a NOT TO DO - Another way would be to use:
divControl.Attributes.Add("style", "height: number");
But don't use this as its messy and the answer by AviewAnew is the correct way.
If your div is an ASP.NET control with runat="server" then AviewAnew's answer should do it. If it's just an HTML div, then you'd probably want to use JavaScript. Can you add the actual div tag to your question?
VB Version:
Class:
Protected divControl As System.Web.UI.HtmlControls.HtmlGenericControl
OnLoad/Other function:
divControl.Style("height") = "200px"
I've never tried the Add method with the styles. What if the height already exists on the DIV?
I find that code gets messy fast when C# code is used to modify CSS values. Perhaps a better approach is for your code to dynamically set the class attribute on the div tag and then store any specific CSS settings in the style sheet.
That might not work for your situation, but its a decent default position if you need to change the style on the fly in server side code.
Check this out : http://stackoverflow.com/questions/1501577/change-css-dynamically