UserControl's Event Handler not firing

五迷三道 提交于 2019-11-30 20:49:43
Dan Appleyard

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!

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

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;

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!