Hi All,
I am calling one function on onBeforeunload event of page. In that function I am showing modal pop up which having message and Yes/No button. on click of any button it will give ajax call and perform some operation. But currently I am facing one issue that this popup is not waiting until the user click on the button. It is proceeding with onunload event of the page.
Please suggest what can be done in this case.
Below is the code.
onbeforeunload="PromptForUnlock()"
function PromptForUnlock(e) {
ExtenderControls.ModalPopup.showModalPopup(
ExtenderControls.ModalTypeEnum.YesNo,
360, 110, true, false,
Resources.Information, '<span style=\"font-size:15px;color:#003366;font-weight:bold;\">' + Resources.AppKeepLock + '</span>',
'checkApplicationUnlock()');
return false;
}
function checkApplicationUnlock() {
var ret = ExtenderControls.ModalPopup.modalPopupResult();
var userID = "";
if (ret == ExtenderControls.ModalPopupResultEnum.No) {
ExtenderControls.ModalPopup.hideModalPopup();
var param = '{"UserID":"' + userID + '"}';
ExtenderControls.ModalPopup.showModalPopup(
ExtenderControls.ModalTypeEnum.Information,
360, 110, false, true, Resources.Loading,
'<span style=\"font-size:15px;color:#003366;font-weight:bold;\">' + Resources.Loading + '</span>', null);
$.ajax({
type: 'POST',
url: 'PageMethods.aspx/SetApplicationLock',
data: param,
contentType: 'application/json; charset=utf-8',
success: function () {
CallBack = true;
},
error: function () {
},
async: false
});
StartTimer();
}
else {
ExtenderControls.ModalPopup.hideModalPopup();
}
CheckForChangesToApplication(Resources.SavePrompt);
}
function StartTimer() {
if (CallBack || TimeElapsed >= Timeout) {
ExtenderControls.ModalPopup.hideModalPopup();
}
else {
window.setTimeout("StartTimer()", 1000);
TimeElapsed++;
}
}