Dynamic Forms???

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Can someone please tell me the best way to create a web form on the fly
according to a users input???

EG: If a user chooses the number 3 from a dropdownlist 3 textbox items are
created... or if they choose 4 for textboxes are created.

Should AI use a repeater or what is the best solution??? I would be grateful
for any advice! The other thing is if the user chooses 3 textboxes and they
are dynamically created how do I create an unique id for each textbox???

Thanks for any advice!
 
Hi Tim,

I feel the best way to create controls is by using a for loop. A repeater
control, according to me would be an overkill. You can still use a repeater
but you need to capture the values in an array / datatable and bind it to the
repeater and then do a databind. But a loop would be sufficient for this.

Label lbl;
for(int i=0;i<User_Defined_Value;i++)
{
lbl = new Label();
lbl.Id = "Label"+i;
}
This should do the trick...

Every control has a property called ID, by which you can set it.

Coming to creating a form on fly ..... its bit tricky..

You need to use add the controls to the page in the page load event or init
event....

HTH,

Need any help, do post a msg back...

Happy Coding
 
Dim Textboxes() as Textbox

redim Textboxes(TextboxCount)

For x=1 to TextBoxCount
Dim Textboxes(x) as New TextBox
TextBoxes(x).Text = "Fill Me out"
Textboxes(x).ID = "Text" & x
PlaceHolder1.Controls.Add(Textboxes(x))
next x

That will create "TextBoxCount" number of textboxes using an array and
using the element value to make the ID's unique.

You can then add each one to a placeholder or other object.
Textboxcount can be a session value passed from a previous page.
 

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

Back
Top