Page LoadComplete event not getting fired

Page LoadComplete event not getting fired, it actually works until you got something wrong. We will get to know later in this post why Page_LoadComplete was not working. So let’s get started.

What was happening in my case that I had one base class (inheriting page class as normal) and that base class was further being inherited on all pages and on that class Page_LoadComplete event was already getting fired.

Now I created new page and I inherited the base class and I had to use the Page_LoadComplete event on that page too, I was done with my code that had to executed on  Page_LoadComplete event

Now point to keep in mind that, at this moment we will have two Page_LoadComplete events one being called from base class and another we just added in new page. In this situation event will get fired on base class but not on page since it’s only get fired one time.

Solution of Page LoadComplete event not getting fired

I know its very important to have load complete event on base class since base class being derived by all classes and that code written in page complete event will be run for all pages but we also need separate Page_LoadComplete event for particular page. How we can call load complete event twice. that’s why I wrote this post to help out folks that are facing same issue.

Now one thing is clear that we can’t have two page load events to be fired, so how we can get this fixed?. Solution is on base class instead registering load complete event we should append the code of page load event with the page’s load complete property, following is the code example please check

protected override void OnInit(EventArgs e)
   Page.LoadComplete += Page_LoadComplete;
void Page_LoadComplete(object sender, EventArgs e)
   // do your magic

Doing this way you can have separate page load complete event since we didn’t register this event instead we’re appending the code that’s it 🙂

Let me know if it helps you, I will be happy to answer any query.

Leave a Reply