rick
rick

Reputation: 21

Add div to specific Div ASP

I would like to add div's and text to a specific DIV with ASP.NET, i have only found code which allowed controls to be added to the body but not to a specific Div.

Upvotes: 0

Views: 927

Answers (2)

joshb
joshb

Reputation: 5220

I'm assuming you want to add controls and text to the div element server-side. If so, you can simply add runat and id attributes to the div and it will be available to you on the server.

For example, if you have a div on your page declared like this:

<div id="MyDiv" runat="server"></div>

You can add text, html content or other controls to it using the following:

MyDiv.InnerText = "some inner text";  // adding text
MyDiv.InnerHtml = "<div>inner html</div>"; // adding html
MyDiv.Controls.Add(new LiteralControl("a literal control")); // adding a control

Upvotes: 2

Joel Coehoorn
Joel Coehoorn

Reputation: 415705

Change the outer div to an <asp:Panel control. A Panel renders to html as a normal div, and will make it easy to add items from server code.

Upvotes: 1

Related Questions