Programmatically created controls not maintaining their state

Discussion in 'ASP .Net' started by mark.norgate@gmail.com, Jul 31, 2006.

Guest

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.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!