Tuesday, September 27, 2011

Page_LoadComplete not being called in a user control

I needed some logic to execute in a page load event after a control event had occurred.

Initially I wrote:

        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            if (newQuestionControl.ShouldShow)
            {
                mpeNewQuestion.Show();
            }
        }


I put a breakpoint and noticed my logic was not being called.

Since I'm in a user control there is no LoadComplete event. I fixed it like this:


        protected void Page_Init(object sender, EventArgs e)
        {
            this.Page.LoadComplete += new EventHandler(Page_LoadComplete);
        }

2 comments:

Rikkiebags said...

Brilliant, thank you for this - spent several hours head-scratching and this is perfect.

Dave Daku said...

Another heaping mound of joyful gratitude here!