刚跟皱键讨论具体怎么判断的问题,其想法与我的不谋而合,都是用一个全局变量来标识。不过后来经过一番研究,发现大可不必。按照如下代码来做
1 function pageLoad(sender,e)
2 {
3//此处e.get_isPartialLoad()即是判断是初始加载还是回发
4 if(e.get_isPartialLoad())
5 {
6 Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitRequestHandler);
7 Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
8 Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
9 }
10 }
2 {
3//此处e.get_isPartialLoad()即是判断是初始加载还是回发
4 if(e.get_isPartialLoad())
5 {
6 Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitRequestHandler);
7 Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
8 Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
9 }
10 }
只e.get_isPartialLoad()就ok了。
另外,Sys.Web.PageRequestManager.getInstance()的几个事件的顺序可以按照如下方式代码来测试一下,它们的顺序为
initializeRequest→beginRequest→ 向服务器端发送数据→接收数据→pageLoading→pageLoad→endRequest
1 function pageLoad(sender,e)
2 {
3 if(e.get_isPartialLoad()==false)
4 {
5 Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitRequestHandler);
6 Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(PageLoadingHandler);
7 Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoadedHandler);
8 Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
9 Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
10 }
11 }
12
13 function PageLoadingHandler(sender,e)
14 {
15 alert("PageLoading");
16 }
17
18 function PageLoadedHandler(sender,e)
19 {
20 alert("PageLoaded");
21 }
22 function InitRequestHandler(sender,e)
23 {
24 alert("InitRequestHandler");
25 }
26
27 function BeginRequestHandler(sender,e)
28 {
29 alert("BeginRequestHandler");
30 }
31
32 function EndRequestHandler(sender,e)
33 {
34 alert("EndRequestHandler");
35 }
2 {
3 if(e.get_isPartialLoad()==false)
4 {
5 Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitRequestHandler);
6 Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(PageLoadingHandler);
7 Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoadedHandler);
8 Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
9 Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
10 }
11 }
12
13 function PageLoadingHandler(sender,e)
14 {
15 alert("PageLoading");
16 }
17
18 function PageLoadedHandler(sender,e)
19 {
20 alert("PageLoaded");
21 }
22 function InitRequestHandler(sender,e)
23 {
24 alert("InitRequestHandler");
25 }
26
27 function BeginRequestHandler(sender,e)
28 {
29 alert("BeginRequestHandler");
30 }
31
32 function EndRequestHandler(sender,e)
33 {
34 alert("EndRequestHandler");
35 }