擔當非同步處理的 PageRequestManager,也是有所謂的生命週期。他共有5種:
Event 順序 | Event 說明 |
1. initializeRequest | Raised before processing of the asynchronous request starts. You can use this event to cancel a postback. |
2. beginRequest | Raised before processing of an asynchronous postback starts and the postback is sent to the server. You can use this event to set request headers or to begin an animation that indicates that the page is processing. |
3. pageLoading | Raised after the response from the server to an asynchronous postback is received but before any content on the page is updated. You can use this event to provide a custom transition effect for updated content. |
4. pageLoaded | Raised after all content on the page is refreshed, as a result of either a synchronous or an asynchronous postback. You can use this event to provide a custom transition effect for updated content. |
5. endRequest | Raised after an asynchronous postback is finished and control has been returned to the browser. You can use this event to provide a notification to users or to log errors. |
攔PageRequestManager5種生命週期的方法:
<script type="text/javascript">
var prm=Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(initializeRequest);
prm.add_beginRequest(beginRequest);
prm.add_pageLoading(pageLoading);
prm.add_pageLoaded(pageLoaded);
prm.add_endRequest(endRequest);
function initializeRequest(sender, initializeRequestEventArgs)
{
alert('initialize function');
}
function beginRequest(sender, beginRequestEventArgs)
{
alert('beginRequest function');
}
function pageLoading(sender, pageLoadingEventArgs)
{
alert('pageLoading function');
}
function pageLoaded(sender, pageLoadedEventArgs)
{
alert('pageLoaded function');
}
function endRequest(sender, endRequestEventArgs)
{
alert('endRequest function');
}
</script>
[程式參考]
沒有留言:
張貼留言