Client-ValueChanged and window.onbeforeunload

1 posts, 0 answers
  1. Andrey
    Andrey avatar
    3 posts
    Member since:
    Aug 2011

    Posted 14 Dec 2011 Link to this post

    Hi,

    I have the following code on my page:

    var isDirty = false;
     
    function OnTextBoxValueChanged(sender, args)
    {
     isDirty = true;
    }
     
    window.onbeforeunload = function ()
    {
     if (isDirty)
     {
       return 'You have unsaved changes on the form.';
     }
    }

    OnTextBoxValueChanged is the handler for RadTextBox's corresponding client event.

    if user changes text in textbox, then moves focus to any other element and then presses 'close tab' in browser - confirmation window appears. This is correct. But the problem appears when user changes text and then immediately presses 'close tab'. In this case onbeforeunload event fires before onvaluechanged and isDirty variable has incorrect value (false) in onbeforeunload handler.

    Am I doing something wrong or is there a workaround for my case?

    Thanks,
    Andrey
Back to Top