Complex form problem!!!

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
 
O

Ollie Riches

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
 
M

Martin Dechev

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top