browse: forums | FAQ
Connecting Tech Pros Worldwide

Hey there! Do you need ASP.NET help?

Get answers from our community of ASP.NET experts on BYTES! It's free.

Add div to asp.net page

shapper
Guest
 
Posts: n/a
#1: May 25 '07
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




Michael Nemtsev
Guest
 
Posts: n/a
#2: May 25 '07

re: Add div to asp.net page


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

SHello,
S>
SI want to add a div tag with a few properties (class, id, ...) to a
Spage. I would like to build the following block:
S>
S<div id="myid" class="myclass">
S>
S<Asp:TextBox...
S>
S</div>
S>
SI don't want to add the div using Asp:Panel.
S>
SI know I can use literal. But is there another way to define the div
Sand its properties before adding it to the page without using a
Sstring?
S>
SWhat should be the best way to do this?
S>
SThanks,
S>
SMiguel
S>


Closed Thread