Dynamically create Asp:Textbox

Cowscmhm

New member
Joined
Jul 14, 2003
Messages
1
I have a web page that I would like to switch from ASP to .Net (mostly for the validation). The problem is that I dynamically create a section of the form:

for (i < variable)
<input type=text name="fname<%=i>">
etc....
Next

This does not seem to be possible using ASP:Textbox because the control cannot be defined at runtime. It would be nice if there was a TextBoxList option as there is with radiobuttons and checkboxes. Anyone know if this is possible to create to as a custom control or have any ideas as to how I might implement the above logic in the .Net world?

Thanks for your help
-Chris
 
You can do this to create your TextBoxes in codebehind:

C#:
private void Page_Load(object sender, System.EventArgs e)
{
for (inti=0; i<10; i++)
{
TextBox tb = new TextBox();
tb.id = "tb"+i.ToString();
this.Controls[1].Controls.Add(tb);
}
}
{
 
Back
Top