开发者

Is there a global "onRequestComplete" event when using ASP.Net Update Panels?

I have a master page with a public ShowWaitingDialog property. When set to true, I simply show a modal "Please wait..." overlay when the form is submitted. This is done by registering a client-side function called ShowWaitingDialog() using the following:

Page.ClientScript.RegisterOnSubmitStatement(Page.GetType(), "ShowWaitingDialog", "ShowWaitingDialog()");

As a side no开发者_Python百科te, I also have a function the coder can use if linking to a page that may take a while to load:

public void AttachWaitingDialog(HyperLink HyperLinkControl){
if (this.ShowWaitingDialog)
    HyperLinkControl.Attributes.Add("onclick", "ShowWaitingDialog();");}

These work just fine until an UpdatePanel is introduced onto the page. The dialog is correctly shown when a postback happens inside an update panel. However, it never goes away when the request is complete. I was hoping there was some sort of global complete event that the Microsoft ajax framework uses when making update panels requests. That way I could close my modal overflow when executed. Is there?

I haven't tried it yet, but I guess I could use the ScriptManager to always register a startup script which hides the modal overlay, but I was wondering if there was another way.


You can use Javascript and use the PageRequestManager clientside api provided by Microsoft Ajax framework.

<script type='text/javascript'>

var pageMgr = Sys.WebForms.PageRequestManager.getInstance();

pageMgr.add_beginRequest(BeforeAjaxRequest);
pageMgr.add_endRequest(AfterAjaxRequest);

function BeforeAjaxRequest(sender, args)
{
 alert('MyReqeustStart');
}

function AfterAjaxRequest(sender, args)
{
 alert('MyReqeustEnd');
}

</script>

More Details here: http://msdn.microsoft.com/en-us/library/bb311028.aspx


I'm not sure with UpdatePanels, but you might take a look at the Application_EndRequest method in Global.asax

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜