[Log]ASP.NET之HttpModule 事件执行顺序

ASP.Net下的HttpModule是基于事件的处理模型,这使得我们在选择事件监听和处理的时候有更多选择。下面是对HttpModule有关事件被触发的监测:

有关代码如下

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.SessionState;
using System.Threading;

/// 

///EventTest 的摘要说明
///
public class EventTest : IHttpModule, IRequiresSessionState
{
    public EventTest()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }

    void IHttpModule.Dispose()
    {
        return;
    }

    void IHttpModule.Init(HttpApplication App)
    {
        App.AcquireRequestState += new EventHandler(AcquireRequestState);
        App.BeginRequest += new EventHandler(BeginRequest);
        App.AuthenticateRequest += new EventHandler(AuthenticateRequest);
        App.AuthorizeRequest += new EventHandler(AuthorizeRequest);
        App.Disposed += new EventHandler(Disposed);
        App.EndRequest += new EventHandler(EndRequest);
        App.Error += new EventHandler(Error);
        //App.MapRequestHandler += new EventHandler(MapRequestHandler);
        App.PostAcquireRequestState += new EventHandler(PostAcquireRequestState);
        App.PostAuthenticateRequest += new EventHandler(PostAuthenticateRequest);
        App.PostAuthorizeRequest += new EventHandler(PostAuthorizeRequest);
        //App.PostLogRequest += new EventHandler(PostLogRequest);
        App.PostMapRequestHandler += new EventHandler(PostMapRequestHandler);
        App.PostReleaseRequestState += new EventHandler(PostReleaseRequestState);
        App.PostRequestHandlerExecute += new EventHandler(PostRequestHandlerExecute);
        App.PostResolveRequestCache += new EventHandler(PostResolveRequestCache);
        App.PostUpdateRequestCache += new EventHandler(PostUpdateRequestCache);
        App.PreRequestHandlerExecute += new EventHandler(PreRequestHandlerExecute);
        App.PreSendRequestHeaders += new EventHandler(PreSendRequestHeaders);
        App.PreSendRequestContent += new EventHandler(PreSendRequestContent);
        App.ReleaseRequestState += new EventHandler(ReleaseRequestState);
        App.ResolveRequestCache += new EventHandler(ResolveRequestCache);
        App.UpdateRequestCache += new EventHandler(UpdateRequestCache);
    }

    private void BeginRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:BeginRequest(执行Http请求管线链中第一个事件时发生)");
    }

    private void AcquireRequestState(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:AcquireRequestState(与当前建立会话时发生)");
        if (context.Session["T"] != null)
        {
            response.Write(" + " + context.Session["T"].ToString());
        }
        else
        {
            response.Write(" Session未收到!");
        }
    }

    private void AuthenticateRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:AuthenticateRequest(安全模块建立用户标记时发生)");

    }

    private void AuthorizeRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:AuthorizeRequest(安全模块验证用户授权时发生)");

    }

    private void Disposed(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:Disposed(释放应用时发生)");

    }

    private void EndRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:EndRequest(执行Http请求管线链中最后一个事件时发生)");

    }

    private void Error(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + Error(Error事件时发生)");
    }

    private void PostAcquireRequestState(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:PostAcquireRequestState(已经获得当前请求状态时发生)");
        if (context.Session["T"] != null)
        {
            response.Write(" + " + context.Session["T"].ToString());
        }
        else
        {
            response.Write(" Session未收到!");
        }
    }

    private void PostAuthenticateRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:PostAuthenticateRequest(已建立用户标识时发生)");
    }

    private void PostAuthorizeRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:PostAuthorizeRequest(当前请求的用户已获得授权时发生)");
    }

    private void PostMapRequestHandler(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:PostMapRequestHandler(当前请求事件映射到相应事件后发生)");

    }

    private void PostReleaseRequestState(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + PostReleaseRequestState(完成请求事件并且请求状态已存储时发生)");
    }

    private void PostRequestHandlerExecute(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:PostRequestHandlerExecute(ASP.Net事件执行完毕时发生)");
    }

    private void PostResolveRequestCache(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:PostResolveRequestCache(跳过当前请求并接受来自缓存数据时发生)");
    }

    private void PostUpdateRequestCache(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:PostUpdateRequestCache(事件缓存被更新时发生)");

    }

    private void PreRequestHandlerExecute(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:PreRequestHandlerExecute(页面事件执行前发生)");

        if (context.Session["T"] != null)
        {
            response.Write(" + " + context.Session["T"].ToString());
        }
        else
        {
            response.Write(" Session未收到!");
        }
    }

    private void PreSendRequestContent(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        //response.Write("
" + time + "  + IHttpModule:PreSendRequestContent(向客户端发送内容之前发生)");

    }

    private void PreSendRequestHeaders(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:PreSendRequestHeaders(向客户端发送HttP头之前发生)");
    }

    private void ReleaseRequestState(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:ReleaseRequestState(事件执行完成之后状态处理)");
    }

    private void ResolveRequestCache(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:ResolveRequestCache(从缓存中发生数据请求时)");
    }
    private void UpdateRequestCache(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        HttpRequest request = application.Request;
        HttpResponse response = application.Response;
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        response.Write("
" + time + "  + IHttpModule:UpdateRequestCache(时间执行完毕,为缓存新的事件准备)");
    }

}

需要在web.Config加入

<httpModules>

        <add name="Haha" type="EventTest"/>
<httpModules>

任意Page的代码(aspx)

protected void Page_Load(object sender, EventArgs e)
    {
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        Response.Write("
" + time + "  + Page:Page_Load");
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        Response.Write("
" + time + "  + Page:TextBox1_TextChanged");
        Label1.Text = TextBox1.Text;
    }
    protected void TextBox2_TextChanged(object sender, EventArgs e)
    {
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        Response.Write("
" + time + "  + Page:TextBox2_TextChanged");
        Label2.Text = TextBox2.Text;
    }

    private void Page_LoadComplete(object sender, System.EventArgs e)
    {
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        Response.Write("
" + time + "  + Page:Page_LoadComplete");
    }

    private void Page_Unload(object sender, System.EventArgs e)
    {
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        //Response.Write("
" + time + "  + Page_Unload");
    }

    private void Page_PreInit(object sender, System.EventArgs e)
    {
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        Response.Write("
" + time + "  + Page:Page_PreInit");
    }

    private void Page_Init(object sender, System.EventArgs e)
    {
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        Session["T"] = "来自Page级:Page_Init" + time;
        Response.Write("
" + time + "  + Page:Page_Init");
    }

    private void Page_InitComplete(object sender, System.EventArgs e)
    {
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        Response.Write("
" + time + "  + Page:Page_InitComplete");
    }

    private void Page_PreLoad(object sender, System.EventArgs e)
    {
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        Response.Write("
" + time + "  + Page:Page_PreLoad");
    }

    private void Page_PreRender(object sender, System.EventArgs e)
    {
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        Response.Write("
" + time + "  + Page:Page_PreRender");
    }

    private void Page_PreRenderComplete(object sender, System.EventArgs e)
    {
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        Response.Write("
" + time + "  + Page:Page_PreRenderComplete");
    }

    private void Page_SaveStateComplete(object sender, System.EventArgs e)
    {
        string time = DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond.ToString("000");
        Response.Write("
" + time + "  + Page:Page_SaveStateComplete");
    }

当Page(aspx)页面事件被加载(首次)被加载后的信息

2009-11-22 18:02:35:828 + IHttpModule:BeginRequest(执行Http请求管线链中第一个事件时发生)
2009-11-22 18:02:35:828 + IHttpModule:AuthenticateRequest(安全模块建立用户标记时发生)
2009-11-22 18:02:35:828 + IHttpModule:PostAuthenticateRequest(已建立用户标识时发生)
2009-11-22 18:02:35:828 + IHttpModule:AuthorizeRequest(安全模块验证用户授权时发生)
2009-11-22 18:02:35:828 + IHttpModule:PostAuthorizeRequest(当前请求的用户已获得授权时发生)
2009-11-22 18:02:35:828 + IHttpModule:ResolveRequestCache(从缓存中发生数据请求时)
2009-11-22 18:02:35:828 + IHttpModule:PostResolveRequestCache(跳过当前请求并接受来自缓存数据时发生)
2009-11-22 18:02:35:859 + IHttpModule:PostMapRequestHandler(当前请求事件映射到相应事件后发生)
2009-11-22 18:02:35:859 + IHttpModule:AcquireRequestState(与当前建立会话时发生) Session未收到!
2009-11-22 18:02:35:859 + IHttpModule:PostAcquireRequestState(已经获得当前请求状态时发生) Session未收到!
2009-11-22 18:02:35:859 + IHttpModule:PreRequestHandlerExecute(页面事件执行前发生) Session未收到!
2009-11-22 18:02:35:875 + Page:Page_PreInit
2009-11-22 18:02:35:875 + Page:Page_Init
2009-11-22 18:02:35:875 + Page:Page_InitComplete
2009-11-22 18:02:35:875 + Page:Page_PreLoad
2009-11-22 18:02:35:875 + Page:Page_Load
2009-11-22 18:02:35:875 + Page:Page_LoadComplete
2009-11-22 18:02:35:875 + Page:Page_PreRender
2009-11-22 18:02:35:875 + Page:Page_PreRenderComplete
2009-11-22 18:02:35:953 + Page:Page_SaveStateComplete
Label1(aspx页面的)
Label2(aspx页面的)
2009-11-22 18:02:35:953 + IHttpModule:PostRequestHandlerExecute(ASP.Net事件执行完毕时发生)
2009-11-22 18:02:35:953 + IHttpModule:ReleaseRequestState(事件执行完成之后状态处理)
2009-11-22 18:02:35:953 + PostReleaseRequestState(完成请求事件并且请求状态已存储时发生)
2009-11-22 18:02:35:953 + IHttpModule:UpdateRequestCache(时间执行完毕,为缓存新的事件准备)
2009-11-22 18:02:35:953 + IHttpModule:PostUpdateRequestCache(事件缓存被更新时发生)
2009-11-22 18:02:35:953 + IHttpModule:EndRequest(执行Http请求管线链中最后一个事件时发生)
2009-11-22 18:02:35:953 + IHttpModule:PreSendRequestHeaders(向客户端发送HttP头之前发生)

注意,想使用Session时,必须在AcquireRequestState,PostAcquireRequestState以及PreRequestHandlerExecute事件中.

页面事件被触发

2009-11-22 18:30:05:843 + IHttpModule:BeginRequest(执行Http请求管线链中第一个事件时发生)
2009-11-22 18:30:05:843 + IHttpModule:AuthenticateRequest(安全模块建立用户标记时发生)
2009-11-22 18:30:05:843 + IHttpModule:PostAuthenticateRequest(已建立用户标识时发生)
2009-11-22 18:30:05:843 + IHttpModule:AuthorizeRequest(安全模块验证用户授权时发生)
2009-11-22 18:30:05:843 + IHttpModule:PostAuthorizeRequest(当前请求的用户已获得授权时发生)
2009-11-22 18:30:05:843 + IHttpModule:ResolveRequestCache(从缓存中发生数据请求时)
2009-11-22 18:30:05:843 + IHttpModule:PostResolveRequestCache(跳过当前请求并接受来自缓存数据时发生)
2009-11-22 18:30:05:843 + IHttpModule:PostMapRequestHandler(当前请求事件映射到相应事件后发生)
2009-11-22 18:30:05:843 + IHttpModule:AcquireRequestState(与当前建立会话时发生) + 来自Page级:Page_Init2009-11-22 18:30:03:406
2009-11-22 18:30:05:843 + IHttpModule:PostAcquireRequestState(已经获得当前请求状态时发生) + 来自Page级:Page_Init2009-11-22 18:30:03:406
2009-11-22 18:30:05:843 + IHttpModule:PreRequestHandlerExecute(页面事件执行前发生) + 来自Page级:Page_Init2009-11-22 18:30:03:406
2009-11-22 18:30:05:843 + Page:Page_PreInit
2009-11-22 18:30:05:843 + Page:Page_Init
2009-11-22 18:30:05:843 + Page:Page_InitComplete
2009-11-22 18:30:05:843 + Page:Page_PreLoad
2009-11-22 18:30:05:843 + Page:Page_Load
2009-11-22 18:30:05:843 + Page:TextBox1_TextChanged
2009-11-22 18:30:05:843 + Page:Page_LoadComplete
2009-11-22 18:30:05:843 + Page:Page_PreRender
2009-11-22 18:30:05:843 + Page:Page_PreRenderComplete
2009-11-22 18:30:05:843 + Page:Page_SaveStateComplete
aspx 页面信息
2009-11-22 18:30:05:843 + IHttpModule:PostRequestHandlerExecute(ASP.Net事件执行完毕时发生)
2009-11-22 18:30:05:843 + IHttpModule:ReleaseRequestState(事件执行完成之后状态处理)
2009-11-22 18:30:05:843 + PostReleaseRequestState(完成请求事件并且请求状态已存储时发生)
2009-11-22 18:30:05:843 + IHttpModule:UpdateRequestCache(时间执行完毕,为缓存新的事件准备)
2009-11-22 18:30:05:843 + IHttpModule:PostUpdateRequestCache(事件缓存被更新时发生)
2009-11-22 18:30:05:843 + IHttpModule:EndRequest(执行Http请求管线链中最后一个事件时发生)
2009-11-22 18:30:05:843 + IHttpModule:PreSendRequestHeaders(向客户端发送HttP头之前发生)

以下为摘录,用于加深事件模型的理解

Page 执行中将按照如下顺序激活事件:

Page.PreInit
Page.Init
Page.InitComplite
Page.PreLoad
Page.Load
Page.LoadComplete
Page.PreRender
Page.PreRenderComplete

如果页面从令一个页面继承,如BasePage:System.Web.UI.Page,在BasePage中做了一些扩展,如权限检查,而其他页面从BasePage继承,则BasePage和最终Page的事件激活顺序是:

UI.PreInit
Page.PreInit
UI.Init
Page.Init
UI.InitComplite
Page.InitComplite
UI.PreLoad
Page.PreLoad
UI.Load
Page.Load
UI.LoadComplete
Page.LoadComplete
UI.PreRender
Page.PreRender
UI.PreRenderComplete
Page.PreRenderComplete

如果使用了MasterPage,则MasterPage中的事件和ContentPage中的事件按照下面顺序激活:

ContentPage.PreInit
Master.Init
ContentPage.Init
ContentPage.InitComplite
ContentPage.PreLoad
ContentPage.Load
Master.Load
ContentPage.LoadComplete
ContentPage.PreRender
Master.PreRender
ContentPage.PreRenderComplete

更进一步,如果ContentPage继承BasePage,那么,各事件的执行顺序将变成:

UI.PreInit
ContentPage.PreInit
Master.Init
UI.Init
ContentPage.Init
UI.InitComplite
ContentPage.InitComplite
UI.PreLoad
ContentPage.PreLoad
UI.Load
ContentPage.Load
Master.Load
UI.LoadComplete
ContentPage.LoadComplete
UI.PreRender
ContentPage.PreRender
Master.PreRender
UI.PreRenderComplete
ContentPage.PreRenderComplete

MasterPage UserControlOnTop Page UserControlInPage UserControlOnButtom
  Init      
      Init  
        Init
Init        
    Init    
    Load    
Load        
  Load      
      Lod  
        Load
ControlEvents ControlEvents ControlEvents ControlEvents ControlEvents
    PreRender    
PreRender        
  PreRender      
      PreRender  
        PreRender
  UnLoad      
      UnLoad  
        UnLoad
UnLoad        
    UnLoad    
时间: 2024-10-12 23:40:48

[Log]ASP.NET之HttpModule 事件执行顺序的相关文章

引用asp.net母版页后,母版页和内容页的页面事件执行顺序

如下,经测试得到的执行步骤: 第01步.内容页的 Page_PreInit第02步.母版页的 Page_Init第03步.内容页的 Page_Init第04步.内容页的 Page_InitComplete第05步.内容页的 Page_PreLoad第06步.内容页的 Page_Load第07步.母版页的 Page_Load第08步.母版页或内容页的 按钮点击等回发事件(Master或Content的Button事件不会同时触发)第09步.内容页的 Page_LoadComplete第10步.内容

运行page页面时的事件执行顺序

运行page页面时的事件执行顺序 using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControl

关于js事件执行顺序

关于js事件执行顺序小技巧 js事件执行顺序是js中一个老生常谈的一个话题, 聊这个话题之前我们先谈谈怎么给页面元素绑定我们需要的事件 1.给页面元素绑定事件 a)直接在元素上面加上需要绑定的事件,如 <button type="button" onclick="console.log('111')"></button> 结果如下: 此方法不建议使用,有两方面的原因, 1)此方法绑定的方法必须为一个全局的方法,而通常我们需要绑定的方法都是针对

jquery的AJAX中各个事件执行顺序

jquery的AJAX中各个事件执行顺序如下: 1.ajaxStart(全局事件) 2.beforeSend 3.ajaxSend(全局事件) 4.success 5.ajaxSuccess(全局事件) 6.error 7.ajaxError (全局事件) 8.complete 9.ajaxComplete(全局事件) 10.ajaxStop(全局事件)

jquery ajax 事件执行顺序

jquery中各个事件执行顺序如下: 1.ajaxStart(全局事件) 2.beforeSend 3.ajaxSend(全局事件) 4.success 5.ajaxSuccess(全局事件) 6.error 7.ajaxError (全局事件) 8.complete 9.ajaxComplete(全局事件) 10.ajaxStop(全局事件) Ajax中success与complete的关系 $.ajax({ type: "get|post", url: url, dataType:

asp.net页面事件执行顺序

转自http://www.cnblogs.com/hnlyh/articles/4230388.html C#代码 using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.

System.Web.UI.Page事件执行顺序

#region OnPreInit 第一步(显式重写,文章下面有隐式重写) protected override void OnPreInit(EventArgs e) { //检查 IsPostBack 属性来确定是不是第一次处理该页. //创建或重新创建动态控件. //动态设置主控页. //动态设置 Theme 属性. //读取或设置配置文件属性值. //注意 //如果请求是回发请求,则控件的值尚未从视图状态还原.如果在此阶段设置控件属性,则其值可能会在下一事件中被重写. base.OnPr

Asp.net Mvc (Filter及其执行顺序)

应用于Action的Filter 在Asp.netMvc中当你有以下及类似以下需求时你可以使用Filter功能判断登录与否或用户权限,决策输出缓存,防盗链,防蜘蛛,本地化设置,实现动态Actionfilter是一种声明式编程方式,在Asp.net MVC中它只能应用在Action上Filter要继承于ActionFilterAttribute抽象类,并可以覆写void OnActionExecuting(FilterExecutingContext)和void OnActionExecuted(

aspx 的页面事件执行顺序

aspx页面生命周期事件 Page_PreInit 使用IsPostBack属性确定是否是第一次处理该页:创建动态控件:动态设置Theme属性:读取或设置配置文件属性值等 Page_Init 读取或初始化控件属性 Page_Preload 事件在所有回发数据处理之后但在 Load 事件之前引发 Page_Load 读取和更新控件属性 Control events 处理特定事件,如 Button 控件的 Click 事件 Page_PreRender 对页的内容进行最后更改 Page_Unload