Programmatically created controls not maintaining their state

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

  1. 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.

    Ta, Mark
    , Jul 31, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RWFybCBUZWlncm9i?=

    Maintaining View State For Dynamically Created Controls

    =?Utf-8?B?RWFybCBUZWlncm9i?=, Oct 7, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,919
    =?Utf-8?B?RWFybCBUZWlncm9i?=
    Oct 7, 2004
  2. Tom wilson
    Replies:
    2
    Views:
    2,621
    Tom wilson
    Feb 11, 2005
  3. =?Utf-8?B?UGV0ZSBNb3Nz?=

    Maintaining state with a dynamically created TemplateColumn

    =?Utf-8?B?UGV0ZSBNb3Nz?=, Apr 5, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    911
    =?Utf-8?B?UGV0ZSBNb3Nz?=
    Apr 8, 2006
  4. Earl Teigrob

    Maintaining View State For Dynamically Created Controls

    Earl Teigrob, Oct 7, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    144
    Earl Teigrob
    Oct 7, 2004
  5. Replies:
    3
    Views:
    181
Loading...

Share This Page