locked
Can a server callback cause a page postback? RRS feed

  • Question

  • User495068091 posted

    I have an ASP.NET web form that uses an external provider to perform a task. When that task is complete, it sends a callback to the client. That callback can be accessed by a client script that provides function oncallback(e) {}. Is there a way I can have that script cause a postback of the page so I can get the response back at the server? The sample I have from the vendor just displays the result on the page.

    Suggestions?

    Thanks

    Friday, June 8, 2018 8:25 PM

All replies

  • User2053451246 posted

    You can call the __doPostBack() method manually in your JavaScript callback.  This function exists in all ASP.Net Web Form pages.  Just google it for examples.

    Friday, June 8, 2018 8:56 PM
  • User283571144 posted

    Hi GroupIII-Gary,

    That callback can be accessed by a client script that provides function oncallback(e) {}. Is there a way I can have that script cause a postback of the page so I can get the response back at the server?

    As far as I know, there are mutiple way to use javascript to fired the postback.

    For exmaple, we could use jquery trigger function to trigger the button click event or we could use ajax to send the response to the server webmethod.

    More details, you could refer to below codes:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="../Scripts/jquery-1.9.1.min.js"></script>
        <script>
             //postback to the server with the button click event
            $(function () {
       setInterval(function () { $("#Button1").trigger('click'); }, 3000);});
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:Button ID="Button1" runat="server" Text="Button" style="display:none"  OnClick="Button1_Click" />
            </div>
        </form>
    </body>
    </html>
    

    Result:

    Best Regards,

    Brando

    Tuesday, June 12, 2018 8:10 AM