This is a migrated thread and some comments may be shown as answers.

Client-ValueChanged and window.onbeforeunload

0 Answers 41 Views
Input
This is a migrated thread and some comments may be shown as answers.
Andrey
Top achievements
Rank 1
Andrey asked on 14 Dec 2011, 02:22 PM
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

No answers yet. Maybe you can help?

Tags
Input
Asked by
Andrey
Top achievements
Rank 1
Share this question
or