Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello,

I need some help in adding a UserControl to the panel dynamically.

I am using a UserControl has threee textboxes, when i click add button,It should add the Usercontrol with those three textboxes to the Panel.

It's working fine for the first click, I mean when i click add for the first time it's adding the User control to the Panel,But when i click again , it's just replacing the only textboxes. its not adding a new pair of textboxes to my Panel.

Please help me in adding the User Control.

Thank you guys in advance.
Posted
Comments
Sandeep Mewara 13-Dec-10 3:24am    
Share the code piece. You should be able to add the same user control multiple times.

Are you sure it's replacing them? Not just putting new ones over the top?

If when you create the new text boxes you specify the location relative to the TLHC of the panel, you will have to offset them by some amount top account for the ones you already added.

Put a breakpoint on your Add button, and single step through - you should find it that way.
 
Share this answer
 
Comments
shekhardumala 13-Dec-10 4:07am    
Hi, Thank you for your reply,

I checked it again, when i click the add button first time it's adding the control and when i click the add button again , it's loosing the old control in the post back and adding the control again, so its always loosing the control and adding the control on add button click.
I believe the following URL can help you

Dynamically add and remove user controls[^]
 
Share this answer
 
Comments
shekhardumala 13-Dec-10 4:09am    
hi Thank you for the reply
i have gone through the link.
It does work to add the controlls but.When i enter some values in the textboxes and then realized to add one more, Then it replaces all the text boxes with the new once.

It looses the values entered in the textboxes :(

How to fix it??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900