Postback problem with usercontrol in usercontrol

Discussion in 'ASP .Net Web Controls' started by Mark van Bree, May 30, 2006.

  1. Hi,

    Working with ASP.Net 2.0 with VS2005 and VB.

    I have a problem with a master usercontrol on which I dynamically create a
    usercontrol in a placeholder. The usercontrol displays fine, but the onclick
    event of a button on the dynamically loaded usercontrol does not fire.

    How can I get the onclick event to run the code assigned to the button in
    codebehind?


    Thanks in advance,

    Mark
    Mark van Bree, May 30, 2006
    #1
    1. Advertising

  2. Mark van Bree

    Guest

    If the control is dynamically created then you will need to dynamically
    recreate it on the postback for it's events to be fired even if you are
    no longer interested in displaying it again later.
    You can choose not display the control by removing it from the page
    control heirarchy within the Click handler.
    Else if you do not recreate the control on postback then it's events
    would be silently lost as you discovered.

    Also, when you're recreating the control (button in this case), you
    will need to recreate it exactly so that the framework knows which
    event matches up with which control i.e. IDs must be same the first
    time and subsequnt postbacks.

    Regards,
    Andy
    , May 30, 2006
    #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. huobazi
    Replies:
    1
    Views:
    683
    David Waz...
    Jul 3, 2003
  2. Rajesh Tiwari

    Can we use a usercontrol inside a usercontrol

    Rajesh Tiwari, Aug 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    411
    Rajesh Tiwari
    Aug 12, 2003
  3. nail
    Replies:
    0
    Views:
    1,539
  4. Phl
    Replies:
    2
    Views:
    522
    =?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?=
    Nov 18, 2004
  5. Andreas Klemt

    Problem with UserControl Property in a DataGrid after Postback

    Andreas Klemt, Jul 8, 2003, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    119
    Andreas Klemt
    Jul 8, 2003
Loading...

Share This Page