Add div to asp.net page

S

shapper

Hello,

I want to add a div tag with a few properties (class, id, ...) to a
page. I would like to build the following block:

<div id="myid" class="myclass">

<Asp:TextBox> ...

</div>

I don't want to add the div using Asp:panel.

I know I can use literal. But is there another way to define the div
and its properties before adding it to the page without using a
string?

What should be the best way to do this?

Thanks,

Miguel
 
M

Michael Nemtsev

Hello Shapper,

use HtmlGenericControl like this

Control control = this.FindControl("body");
HtmlControl divControl = new HtmlGenericControl("div");
divControl.Attributes.Add("id","myid");
divControl.Attributes.Add("class","myclass");
control.Controls.Add(divControl);




---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

S> Hello,
S>
S> I want to add a div tag with a few properties (class, id, ...) to a
S> page. I would like to build the following block:
S>
S> <div id="myid" class="myclass">
S>
S> <Asp:TextBox> ...
S>
S> </div>
S>
S> I don't want to add the div using Asp:panel.
S>
S> I know I can use literal. But is there another way to define the div
S> and its properties before adding it to the page without using a
S> string?
S>
S> What should be the best way to do this?
S>
S> Thanks,
S>
S> Miguel
S>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top