Brijesh Patel
Brijesh Patel

Reputation: 2958

Create Dynamical Div tag in ASP.Net

I am developing Web Application. In that i am using so many Div to open pop ups. Now my requirement is to create dynamic Div for that popup and all the content of that div comes from the Database.

So can anyone tell me how to create Div dynamically programatically?

My Sample code for Div..

 <div id="Popup" runat="server" class="hidden-content">
            <table width="auto">
                <tr>
                    <td style="font-size: 20px; font-weight: bold; text-align: center;">
                        <p>
                        </p>
                        <b>Diabetes</b>
                    </td>
                </tr>
                <tr>
                    <td style="font-size: 15px; text-align: left;">
                        <p>
                            Type I diabetes (also known as juvenile diabetes) is the less common form of diabetes.
                            It usually is diagnosed during childhood or teen years and requires treatment with
                            insulin.
                        </p>
                    </td>
                </tr>
            </table>
        </div>

Upvotes: 0

Views: 6233

Answers (4)

Sunny
Sunny

Reputation: 3295

I was working on a web application in which i need same thing as you require from here you will get some idea and make some modifications as per your requirement.Check my article here

If you have any doubt then ask.

Thanks :-)

Upvotes: 0

SCB
SCB

Reputation: 3084

I would insert either a PlaceHolder or a Literal control into you page and insert the html controls/text on PageLoad or PageRender.

If you use the Placeholder control you can create the content using the HTML controls in System.Web.UI.HtmlControls.

By using the Placeholder control, you could also write a custom WebControl that you could re-use in other locations within your site. This could then be added to the placeholder control at runtime.

For a liteal, you can just append the control div HTML as text.

Upvotes: 1

Nickoli Roussakov
Nickoli Roussakov

Reputation: 3409

You need to use the defined server control called asp:Panel, which gets rendered as a div. Create your panels programatically and add them to your page: e.g. Page.Controls.Add(myPanel);

Upvotes: 0

V_B
V_B

Reputation: 1569

you can add html using stringbuilder Use below cose to add html programmatically.

 using System.Text;

 StringBuilder strdiv = new StringBuilder();
 strdiv.Append("Put your Html here");
 strdiv.Append("Add much as you want ");

after that assign that stringbuilder to label so get one label in html with id "htmllabel" Add below line to append html in your label.

  htmllabel.Text = strdiv.ToString();      

Upvotes: 0

Related Questions