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?
3 Answers. Show activity on this post. The content page load event will fire before the master page load event.
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.
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.
Page_Load() method is called after a preLoad event. With Page_Load() you can set default values or check for postBacks etc.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With