Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add a div to container div in c# code behind

Tags:

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

like image 859
ErnieStings Avatar asked Jul 22 '09 14:07

ErnieStings


People also ask

How do you place a div to the right of another div?

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.

What is div container?

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!

How do I put divs side by side?

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.

How do I create a div?

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.


2 Answers

//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); } 
like image 60
Jacob O'Brien Avatar answered Sep 18 '22 01:09

Jacob O'Brien


Panel myChildPanel = new Panel(); myContainerPanel.Controls.Add(myChildPanel); 
like image 28
Matthew Vines Avatar answered Sep 21 '22 01:09

Matthew Vines