以下是主页与内容页合并时发生事件的顺序:
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.
但为什么母版页在PreInit
没有ASP.NET
事件?
Masterpage没有PreInit方法。
您可以采用多种替代方案。
1,为所有其他要继承的页面创建一个公共基页类,在该类中设置theme属性; http://www.odetocode.com/Articles/450.aspx
母版页继承:System.Web.UI.MasterPage
并且根据此MasterPage
类的设计,没有为此类定义此类PreInit
事件。
母版页从Control类派生,如下面的层次结构所示:
System.Object
System.Web.UI.Control
System.Web.UI.TemplateControl
System.Web.UI.UserControl
System.Web.UI.MasterPage
因此,正如现在可以猜到的那样,Master页面的行为和实质上被视为一个控件,并具有类似于其他asp.net服务器控件的事件。
一个建议阅读是this
。
活动顺序如下:
有关详细信息,请参阅以下链接;
http://getmscode.blogspot.in/2014/11/sequence-of-events-in-master-page-and.html
与UrlMapping模型相同,创建一个应由IHttpModule生成的类,然后将其referance添加到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>