C# – UserControl’s Event Handler not firing


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 missing here?

Containing ASPX page:

protected override void OnPreRender(EventArgs e)
    if (MultiView1.ActiveViewIndex == 2) //If the tab is selected, load control
        Control Presenter = LoadControl("Presenter.ascx");


override protected void OnInit(EventArgs e)
    Retry.Click += this.Retry_Click; //This is a .Net 2.0 project

protected void Retry_Click(object sender, EventArgs e)
    //This never fires

Best Solution

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!

Related Question