Click here to Skip to main content
14,666,374 members
Rate this:
Please Sign up or sign in to vote.
See more:

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.
Sandeep Mewara 13-Dec-10 3:24am
Share the code piece. You should be able to add the same user control multiple times.

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
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.
Rate this:
Please Sign up or sign in to vote.

Solution 2

I believe the following URL can help you

Dynamically add and remove user controls[^]
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100