I'm trying to use onbeforeunload to check if the user is exiting a form before saving changes.
I'm using the AjaxPanel - But onbeforeunload is called on every single ajax request.
How can I test if the pages is REALLY being unloaded ? Help...........
7 Answers, 1 is accepted
This is indeed odd since the onbeforeunload browser event should be raised only when you attempt to close the browser window. I performed a quick test under IE/FF using the latest version of RadControls for ASP.NET AJAX and the event was not fired on ajax requests. Here is the code I used:
Can you please verify that on your machine? Any further details regarding your particular configuration settings can help us determine the reason for the abnormality and address it asap.
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I'm having the same problem.
I'm using a RadDataPager with AJAX and the window.onbeforeunload function is being fired before the "OnRequestStart" event of my RadAjaxManager. Here is the code:
The onbeforeunload function is fired on AJAX calls in IE9 but not in Chrome nor FireFox.
The described issue is browser behavior. However, I have assembled a sample project demonstrating how the problem could be resolved. The idea is to handle document.click event and check if the event target is ajax initiator which will determine the behavior in the onbeforeunload event.
the Telerik team
Glad you replied, thanks a lot!
"Error: Unable to get value of the property 'target': object is null or undefined"
With Chrome, the onClick event is MouseClick but unfortunately, it is undefined in IE 9.
Got a solution?
- The " while (targ && !targ.id) " loops until the RadDataPager element is reached.
- The function exits if it is not IE, since only IE Ajax calls will make it to the "onbeforeunload" function.
- The "onbeforeunload" function must reset the "isIEAjaxRequest" variable.
Still thanks for the help!
(see code below)