Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET page 'Page_Load' firing before Master Page's 'Page_Load' event?

Tags:

On my Master Page, I have a little method in the Page_Load event that checks to see if a user is logged in, and redirects them to the Login page if not.

The problem is that for some of my pages the Page_Load events presume a users logged are in, and these events seems to fire before the login check in the master page, which causes errors.

What are some ways around this? Any events I can use other than Page_Load in my pages, that'll fire after the master page?

like image 562
Chris Avatar asked Apr 08 '11 10:04

Chris


People also ask

Which page loads first master or content?

3 Answers. Show activity on this post. The content page load event will fire before the master page load event.

At which event of page life cycle the master page is loaded?

Master pages behave like child controls on a page: the master page Init event occurs before the page Init and Load events, and the master page Load event occurs after the page Init and Load events.

In which of the page event we can set the masterpage of the page at runtime?

Yes. You can assign a master page dynamically during the PreInit stage. Because the master page and content page are merged during the initialization stage of page processing, a master page must be assigned before then.

What is Pageload in C#?

Page_Load() method is called after a preLoad event. With Page_Load() you can set default values or check for postBacks etc.


1 Answers

You have a rich Page Cycle with lots of events to use. Perhaps you could use Page_Init to check if the user is logged-in in the Master Page. Or use Page_PreRender in the other pages.

like image 109
Alessandro Avatar answered Nov 04 '22 07:11

Alessandro