Complex form problem!!!

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

Guest

Can someone please tell me how I add multiple instances of a user control
into a form!

Say I have a drop down list and a user chooses the value 3 from the
dropdownlist.

I want the user control to be addred into a form 3 times! The problem is all
the input fields need to have unique names etc etc!

Can someone please tell me how I can achieve this???

I'm a little stuck with this and would appritiate any help!

I can't seem to find any info on the web about creating dynamic forms like
this...

Thanks
 
You could have a place holder control
(System.Web.UI.WebControls.PlaceHolder) and add them into this.

e.g.


.....
int create = 3;
for(int i = 0; i < create; i++)
{
myControl ctrl = (myControl)Page.LoadControl("myControl.ascx")
myPlaceHolder.Add(ctrl);
}

HTH

Ollie Riches
 
Hi,

You can add the usercontrols dynamically like this, for example:

System.Web.UI.Control control1;
for(int i = 0; i < 3; i++)
{
control1 = LoadControl("filename.ascx");
SomePlaceHolder.Controls.Add(c);
}

About your second concern: if you use server-side form controls in your
usercontrol in question, these are guaranteed to have unique IDs when
rendered.

Hope this helps
Martin Dechev
ASP.NET MVP
 
Back
Top