ASP.NET, C#
As the title suggests I was wondering if anyone knew how to programatically (c# code behind file) add a div to another a container div (in the aspx page).
Thanks in advance
Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.
The <div> tag defines a division or a section in an HTML document. The <div> tag is used as a container for HTML elements - which is then styled with CSS or manipulated with JavaScript. The <div> tag is easily styled by using the class or id attribute. Any sort of content can be put inside the <div> tag!
To position the divs side by side, we are using the float property to float each . float-child element to the left. Since they are both floating to the left, they will display side by side if there's enough space for both to fit.
With the div tag, you can make various shapes and draw anything because it is easy to style. To make a square with div tag, you first need to define an empty div tag and attach a class attribute to it in the HTML. In the CSS, select the div with the class attribute, then set an equal height and width for it.
//create new instance of div and set all the values like the ID Check out the short Code example. It worked for me to create Divs in a web add
System.Web.UI.HtmlControls.HtmlGenericControl NewDiv = new System.Web.UI.HtmlControls.HtmlGenericControl(); NewDiv.ID = "divcreated";
or
protected void Page_Load(object sender, EventArgs e) { System.Web.UI.HtmlControls.HtmlGenericControl createDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV"); createDiv.ID = "createDiv"; createDiv.Style.Add(HtmlTextWriterStyle.BackgroundColor, "Yellow"); createDiv.Style.Add(HtmlTextWriterStyle.Color, "Red"); createDiv.Style.Add(HtmlTextWriterStyle.Height, "100px"); createDiv.Style.Add(HtmlTextWriterStyle.Width, "400px"); createDiv.InnerHtml = " I'm a div, from code behind "; this.Controls.Add(createDiv); }
Panel myChildPanel = new Panel(); myContainerPanel.Controls.Add(myChildPanel);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With