'In ASP.NET, After Selecting "Stay On This Page" nothing is working

I am using this code for preventing user to leave the page if there is any changes on the form in SharePoint FarmApplication

 <script>
    var formDirty = false;
    window.onbeforeunload = function () {

      if (formDirty) {
            return "You have unsaved changes on the page";
        }
    };
</script>

But, after user select "stay on this page", nothing is working like Buttons or DropDowns. Actually the form can not post anything to server.

What is going wrong with this code?



Solution 1:[1]

Check if this script even fired. Also here is a good guide with examples about asp.Net form dirty confirmations.

<script>
    var formDirty = false;
    window.onbeforeunload = function () {
        var confirmMsg = undefined;
        if (formDirty) {
            confirmMsg = "You have unsaved changes on the page";
        }
        return confirmMessage;
    };
</script>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 aleha