1

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="ScriptManager1" 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.

1 Answer 1

1
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 :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.