1

I am trying to generate an html div in asp.net.

Since a div is considered as an HtmlGenericControl, I tried using that but don't know how to define the type of control, therefore it always generates a "span".

Any ideas on how I can define it as a div?

3 Answers 3

4

Just a quick Google query gave me this:

HtmlGenericControl div = new HtmlGenericControl("div");
Sign up to request clarification or add additional context in comments.

Comments

3

If you want to define it in your codebehind you can use:

HtmlGenericControl myDiv = new HtmlGenericControl("div");
//You can now put this control in the children of another control by using
myOtherControl.Children.Add(myDiv); //for example a placeholder or panel

In your ASPX page you can also create a div which is accessible in your code behind by using:

<div runat="server" ID="DivMyDiv"></div>

1 Comment

This answer deserves something. +1
2

An <asp:Panel></asp:Panel> renders as a <div></div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.