Which event called first? Master Page Page_Load or Content Page Page_Load
Asked Answered
L

3

47

I have a Master page and a webpage that uses the Master page.

In both I have a Page_Load event handler.

In which order are the Page_Load handlers called? Content first then Master or Master first then content?

Lepton answered 17/12, 2010 at 11:56 Comment(1)
Why not simply try it out? Create a page with a master page, handle both events, set breakpoints and run your debugger.Sept
V
93

The content page load event will fire before the master page load event.

See here for full order (MSDN: Events in ASP.NET Master and Content Pages)

Copying incase link goes dead:

The following is the sequence in which events occur when a master page is merged with a content page:

  1. Content page PreInit event.
  2. Master page controls Init event.
  3. Content controls Init event.
  4. Master page Init event.
  5. Content page Init event.
  6. Content page Load event.
  7. Master page Load event.
  8. Master page controls Load event.
  9. Content page controls Load event.
  10. Content page PreRender event.
  11. Master page PreRender event.
  12. Master page controls PreRender event.
  13. Content page controls PreRender event.
  14. Master page controls Unload event.
  15. Content page controls Unload event.
  16. Master page Unload event.
  17. Content page Unload event.
Vanburen answered 17/12, 2010 at 11:59 Comment(1)
Whats important to notice here is controls load event fire in different sequence than other events. Master page's controls load event fire before Content page controls Load event.Aorangi
K
10

As far as MasterPage is indeed a user control all rules applied to it as for user controls:

alt text

Kiefer answered 17/12, 2010 at 11:57 Comment(0)
W
2

Master pages run Page_Load() from the deepest level of nesting outwards. So your nested webpage will first run the page_load event.

Waxbill answered 17/12, 2010 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.