UserControl's Event Handler not firing

后端 未结 4 1839
攒了一身酷
攒了一身酷 2021-01-05 15:23

I dynamically load a UserControl into a View that\'s in a MultiView control. Although the UserControl adds an event handler, the event never fires.

What am I missin

相关标签:
4条回答
  • 2021-01-05 16:06

    Postback event handling is done before rendering so the control is not present in the page in your case.

    The life cycle events are fired in this order (skipped a few):

    1. Init
    2. Load
    3. PreRender
    4. Unload

    And event handling is done between Load and PreRender (in case some events change the way the page should be rendered, it makes sense).

    So just move your code that loads the Retry control to Load or Init.

    Reference: Asp.Net Page Life Cycle Overview

    0 讨论(0)
  • 2021-01-05 16:10

    The control must be visible initially to be able to enter in OnPreRender event. but maybe you want it to be unvisible. the be sure to have EnableViewState = false;

    0 讨论(0)
  • 2021-01-05 16:12

    I am thinking it is not firing because you are loading the control in your page's prerender event. Upon postback, the control is being lost because there is no view state for it. Therefore there is no control to fire its event. Try to load the control in the page's init event. Let us know what happens!

    0 讨论(0)
  • 2021-01-05 16:12

    It sounds like the control is not being added after each post back, i would take out the if statement in the containing aspx page to see if that fixes the issue...im assuming Retry is a button?

    0 讨论(0)
提交回复
热议问题