Events in ASP.NET Master and Content Pages
Both master pages and content pages can contain event handlers for controls. For controls, events are handled locally—a control in a content page raises an event in the content page, and a control in the master page raises an event in the master page. Controls events are not sent from the content page to the master page. Similarly, you cannot handle an event from a master page control in a content page.
In some cases, the same event is raised in both the content and the master page. For example, both pages raise Init and Load events. The general rule for how events are raised is that the initialization events are raised from the innermost control to the outermost one, and all other events are raised from the outermost control to the innermost one. It is helpful to remember that the master page is merged into the content page and treated as a control in the content page.
The following is the sequence in which events occur when a master page is merged with a content page:
-
Content page PreInit event.
-
Master page controls Init event.
-
Content controls Init event.
-
Master page Init event.
-
Content page Init event.
-
Content page Load event.
-
Master page Load event.
-
Master page controls Load event.
-
Content page controls Load event.
-
Content page PreRender event.
-
Master page PreRender event.
-
Master page controls PreRender event.
-
Content page controls PreRender event.
-
Master page controls Unload event.
-
Content page controls Unload event.
-
Master page Unload event.
-
Content page Unload event.
The sequence of events in master and content pages rarely is important for you as page developer. However, if you are creating event handlers that depend on the availability of certain controls, you will find it helpful to understand the event sequence in master and content pages.
Source: MSDN