Hi,
I'm trying to do the following :
If the user decides to press x of the Explorer (close) , while running my web application , I added a message asking is he sure
want to do it.
But my problem was that each button pressed on screen , caused this message to apper.
So , what I did is wrote the following functions and used them in order to prevent appearance of the message
In each button that appears on the page i added event :
OnClientClick
="javascript:ToggleBeforeUnload();"
BUT WHEN I'M TRYING TO SORT COLUMNS IN GRID , I STILL GET THE MESSAGE :(
I need your advise please on which even I must run ToggleBeforeUnload() or is there another solution ?
Thanks a lot !
--------- The functions I've wrote -------------
var
suppressWarningMsg = false;
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
function BeginRequestHandler(sender, eventArgs)
{
suppressWarningMsg =
true;
}
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, eventArgs)
{
suppressWarningMsg =
false;
}
function ConfirmExit()
{
if (!suppressWarningMsg)
{
return 'SURE WANNA EXIT ?;
}
}
window.onbeforeunload = ConfirmExit;
var onOff = false;
function ToggleBeforeUnload(onOff)
{
if (onOff == true)
{
window.onbeforeunload = ConfirmExit;
// Activate beforeunload event handler
}
else
{
window.onbeforeunload =
null;
}
}