Dynamically created control disappears after postback.

Discussion in 'ASP .Net' started by Sami Rehman, Sep 3, 2007.

  1. Sami Rehman

    Sami Rehman Guest

    Hi,
    I am creating some web user controls dynamically Using
    LoadControl("ABC.ascx")
    My user control contains 2 drop down list, 2nd one is loaded based on the
    selection in the 1st one.

    However whenever I make the selection in the 1st one, the control disappears
    after the post back. I tried setting the EnableViewState=true but even that
    did not help..
    UCTemp ucTemp = (UCTemp)LoadControl("UCTemp.ascx");
    ucTemp.EnableViewState = true;
    plhInput.Controls.Add(ucTemp);

    Does any one know why this is happening?

    -Sami
    Sami Rehman, Sep 3, 2007
    #1
    1. Advertising

  2. "Sami Rehman" <> wrote in message
    news:%...

    > Does any one know why this is happening?


    Dynamically created controls do not survive a postback - they need to be
    recreated each time the page loads, irrespective of how it loads.

    In addition, if they need to be wired up to events, they need to be created
    before the Page_Load event e.g. in the Page_Init event...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Sep 3, 2007
    #2
    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. Guadala Harry

    User Control Disappears After PostBack - Why?

    Guadala Harry, Jul 1, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    10,198
    Guadala Harry
    Jul 2, 2004
  2. Ryu
    Replies:
    1
    Views:
    3,219
    Lucas Tam
    Aug 18, 2004
  3. msimmons
    Replies:
    0
    Views:
    470
    msimmons
    Jul 16, 2009
  4. Svetoslav Vasilev

    Static user control disappears after postback

    Svetoslav Vasilev, Nov 19, 2007, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    955
    Svetoslav Vasilev
    Nov 19, 2007
  5. Hagai Amiel via .NET 247

    Data Grid Disappears after postback

    Hagai Amiel via .NET 247, Oct 17, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    154
    Scott Mitchell [MVP]
    Oct 18, 2004
Loading...

Share This Page