Link to home
Start Free TrialLog in
Avatar of aspnetdev
aspnetdev

asked on

OnBeforeUnload .....

Hi,
I have an asp.net web page...and it has following script on the HTML <script> block
<script>
  var needToConfirm = <%= jsNeedToConfirm.ToString().ToLower() %>;
  window.onbeforeunload = confirmExit;
  function confirmExit()
    {
        if (needToConfirm )
        {
            return "Test";
        }
}
</script>
and in the code behind(im using C#) on the page_load event the variable
bool jsNeedToConfirm = true;
everything looks good till now....BUT...i have an asp.net button and in the click event of that button im setting jsNeedToConfirm = false;....now the problem im facing is that when im clicking the Save button....even before the click event is called the alert window is being popped up...and then its going to Click event of the button and setting the jsNeedToConfirm = false......can any one tell me what can be the problem or anyother suggestions.....
Prompt help on this wud be much appreciated...
Thanks
ASKER CERTIFIED SOLUTION
Avatar of aspnetguy
aspnetguy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial