Why master page doesn't have PreInit event in ASP.NET?

Viewed 9275

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.

But why master page doesn't have a PreInit event in ASP.NET?

4 Answers

Same as UrlMapping model, create a class that should be generated by IHttpModule, then add its referance to Web.config

public class MasterPageModule: IHttpModule
{    
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}

void context_BeginRequest(object sender, EventArgs e)
{
 //your code
}
}


<httpModules>
   <addname="MasterPageModule"type="MasterPageModule"/>
</httpModules>
Related