Does master page get called first?

12,426

Solution 1

Sorry for just quoting, but i don't know what to add:

Individual ASP.NET server controls have their own life cycle that is similar to the page life cycle. For example, a control's Init and Load events occur during the corresponding page events.

Although both Init and Load recursively occur on each control, they happen in reverse order. The Init event (and also the Unload event) for each child control occur before the corresponding event is raised for its container (bottom-up). However the Load event for a container occurs before the Load events for its child controls (top-down). 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.

http://msdn.microsoft.com/en-us/library/ms178472.aspx

enter image description here

Solution 2

Execution Priority

  1. Content Page
  2. Master Page
  3. User Control

Solution 3

Most page events will get called before the corresponding ones on the master page are (in essence the master page is considered a part of the page it is linked to - it is a user control).

See ASP.Net 2.0 - Master Pages: Tips, Tricks, and Traps on OdeToCode for details.

Share:
12,426
Serguei Fedorov
Author by

Serguei Fedorov

Updated on June 06, 2022

Comments

  • Serguei Fedorov
    Serguei Fedorov almost 2 years

    I would assume this is true, but wanted to throw this question up. Is the master page executed first in ASP.NET, or does the page which is getting retrieved?

    I am asking because I want some processing to be done in the master page, results of which are loaded into a static object and which can then be used by the called page (for instance user data)

  • IrishChieftain
    IrishChieftain about 12 years
    Master page is actually a user control :)
  • qxotk
    qxotk over 3 years
    I think it's OK to quote the documentation while also providing a link. The quote brings reader to solution more quickly - plus, I believe you likely streamlined the doc, given the OP's question as context. I found the detail to my answer in the image you put up front in your answer. Makes for a useful post.