How to Detect ASP.Net Asynchronous PostBack and its settings like control and UpdatePanel that caused PostBack and the using PageRequestManager
Events in JavaScript and here is an example of what I am doing :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManag开发者_运维百科er1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID = "Button1" EventName = "Click" />
</Triggers>
</asp:UpdatePanel>
</form>
<script type="text/javascript">
//////////////
//some javascript code
/////////////
</script>
</body>
</html>
What I want is to use JavaScript to detect this post back.
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm != null) {
prm.add_beginRequest(function (sender, e) {
//Event raised when the Async Postback is started.
//Detect whether the request is Async
var isAsync = sender._postBackSettings.async;
//Detect Id of the control that caused the postback.
var controlId = sender._postBackSettings.sourceElement.id;
//Id of the updatepanel that caused the postback
var updatePanelId = sender._postBackSettings.panelID.split('|')[0];
});
}
prm.add_endRequest(function (sender, e) {
if (sender._postBackSettings.panelsToUpdate != null) {
//Event Raised when the Async Postback is completed.
}
});
put this and tel me the result :) you know that the same article is posted in this link with the same code : http://www.aspsnippets.com/
if you do not understand ask for explaining :)
精彩评论