dynamic controls creation - issue

S

Sri

Hi,

I need to create controls dynamically on click of a button.
When the user click on a button, I need to create a text box, dropdown
list and check box in a row. Additional row has to be created with the
controls on each click of the button. I am able to recreate the
controls each time on Page_load event by maintaining the number of rows
as a Viewstate variable. But I am not able to retain the values entered
in the textbox/dropdownlist. How to retain the values in the
dynamically created controls? I tried with having ViewState variable
for each and every control. But somehow it is not retained. Please let
me know if there is any way to achieve this.

Thanks
Sri
 
M

mark.norgate

Hi

I had a similar problem which I fixed.

I would suggest that you put your text box, dropdown and check box in a
user control and add that dynamically. Instead of just doing simply
Controls.Add(myControl), you need to load the "whatever.ascx" using:

myControl = LoadControl("whatever.ascx");
Page.Controls.Add(control);

Make sure you do this in your CreateChildControls() method on your
page. You should then find that the controls maintain their state and
so on without your having to intervene manually. If they don't, there's
something you're not doing right...

Hope this helps,

Mark
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top