locked
Ajax call to Code-Behind not working before browser close event RRS feed

  • Question

  • I am working on a Silverlight 4.0 In-browser Application. I need to bring up a pop-up on click of the Close(Cross button or Alt+F4) Event. As the Close Event happens on the local browser, so none of server side events are getting triggered on the Close event. I was trying to use OnBeforeUnload Event of JavaScript on the Default.aspx file as mentioned below:

    function areYouSure() {
            $
    .ajax({
                type
    : "POST",
                async
    : false,
                url
    : "default.aspx/GetDialogStatus",
                data
    : "{}",
                contentType
    : "application/json; charset=utf-8",
                dataType
    : "json",
                success
    : function (msg) {
                   
    if (msg.d)
                   
    {
                        confMessage
    = "Unsaved Changes error message";
                   
    }
                   
    else {
                        confMessage
    = nochanges;
                   
    }
               
    },
                error
    : function(error) {
                    alert
    (error);
               
    }

           
    });

           
    return confMessage;
       
    }

       
    var areYouReallySure = false;        
        $
    (document).ready(function () {
            window
    .onbeforeunload = areYouSure;
       
    });

    For the Code Behind:

    [WebMethod]
       
    public static bool GetDialogStatus()
       
    {
           
    if(**Business Condition Satisfies**)
           
    {
               
    return true;
           
    }
           
    else
           
    {
               
    return false;
           
    }
       
    }

    When checking on the local environment the code just works fine. But, when deployed to the Dev, Test Servers, the pop-up is not coming up and we are getting seeing an authentication pop-up when the ajax call happens. Can anybody have faced similar issue?


    Warm Regards Ankit Gupta

    Friday, September 1, 2017 1:50 PM

All replies

  • Hi Anlitg4u,

    Since this issue occurs after deploying to the Dev, Test Servers, please try create a common ASP.NET project use the same  OnBeforeUnload Event of JavaScript in ASP.NET project and deploy to the Dev, Test Servers. This could help us confirm whether this issue related to the Dev, Test Servers or the Silverlight project.

    And please share a screenshot for the authentication pop-up on the Dev, Test Servers to help us understanding what does it need to authentication.

    In addition, please tell us what's the Windows version and what browser do you use on the Dev, Test Servers. I will build a VM based on your environment and deploy on a Silverlight application with your code to reproduce this problem in my side.

    Best Regards,
    Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, September 4, 2017 7:41 AM
    Moderator