Add div to asp.net page

  • Thread starter Thread starter shapper
  • Start date Start date
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
 
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>
 
Back
Top