Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am writing a javascript code where when user clicks on other buttons or close the browser after data is filled by saved button is not clicked, a message is shown that tells user "if they wish to stay or exit. on exit all data will be lost". my javascript is .
XML
<script type="text/javascript">
    var reconnect = false;
    window.onfocus = function () {
        if (reconnect) {
            reconnect = false;
            alert("Perform an auto-login here!");
        }
    };
    window.onbeforeunload = function () {
        var msg = "Are you sure you want to leave?";
        reconnect = true;
        return msg;

    };
</script>


this script provides option to either stay on page or leave page.. now when user clicks on leave page,how can i set a code here that records this option and send it in server side.. i am planning to implement hiddenfield in client side but what i am not clear is in how to set the option choosen by user in to hidden field.. any help or alternative..?? thanks in advance
Posted

1 solution

You can use jQuery Ajax and call one WebMethod in .cs page and pass any value to that method.

Refer - Using jQuery to directly call ASP.NET AJAX page methods[^] for example and explanation.
 
Share this answer
 
v2
Comments
Codes DeCodes 29-Jan-14 3:35am    
thanks man.. i will try this and response you...
Glad to hear that. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900