Click to See Complete Forum and Search --> : Creating Multiple Controls dynamicaly


Clapy2202
April 18th, 2003, 04:47 PM
I am trying to create a webpage where the user will enter the number of textboxes to be displayed. After that I have to create the textboxes.

I tryed the following code (to create one textbox)

this.Controls.Add(new LiteralControl("< h3 >Value: "));

TextBox box = new TextBox();
box.Text = "0";
this.Controls.Add(box);

this.Controls.Add(new LiteralControl("< /h3 >"));

but in return I recive the following error message:
Control '_ctl0' of type 'TextBox' must be placed inside a form tag with runat=server

Can anyone tell me how I can do that?

V. Lorenzo
April 25th, 2003, 12:15 PM
Hi:

If you're creating the controls in a page, the Page's Controls property may be a little tricky to handle. Just place a PlaceHolder control on your page and insert the dynamically created controls using the PlaceHolder's Controls property, just like you did in your code.

VLorz
p.d. The place holder does not add any additional HTML tag, it's just that, a "Place Holder".