Programmatically created controls not maintaining their state

M

mark.norgate

Hi

I'm having a problem in adding controls to a page programmatically in
response to a button click.

Composite user controls added programmatically in the
CreateChildControls() method work fine; they maintain their state as
expected. Cool and groovy. However, since CreateChildControls() is
called before the method that responds to the button click, say
AddControl_Click(), for some reason, this control does not maintain its
state after the next postback (it contains lots of dropdowns and so
on).

Why is this? In my AddControl_Click(), I'm doing
ProjectPlaceHolder.Controls.Add( projectDetails ), and then populating
the various controls within this projectDetails control with data.
Which is all working great. This second control appears as expected
with all the relevant data.

However, when I then click the button again, a third control appears,
with the data as expected, but the second control I just added loses
all of its data: it's not maintaining its state.

Can anyone tell me why this is and what I can do about it? I am
implementing INamingContainer on this composite control.

Ta, 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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top