This topic is locked
[SOLVED]

Add warning with opt out when user closes an edit popup with unsaved changes

8/23/2026 03:40:39
General Tips and Tricks
J
jMullally author

Sharing is caring. I find it helpful to provide a warning with opt out when the user attempts to close an edit popup with unsaved changes and don't see that functionality included by Xlinesoft. I attain that capabiity by adding the following canned javascript to my Edit Page OnPageLoad events.

var formChanged = false;

// Detect any changes in form controls
$("input").on('change', function() { formChanged = true; });
$("select").on('change', function() { formChanged = true; });
$("textarea").on('change', function() { formChanged = true; });

// Reset flag when saving
pageObj.on('beforeSave', function() {
formChanged = false;
return true;
});

// Intercept close/cancel actions
$('.modal-header .close, [id^="closeButton"]').on('click', function(e) {
if (formChanged) {
if (!confirm("You have unsaved changes. Are you sure you want to close?")) {
e.stopPropagation();
e.preventDefault();
return false;
}
}
});
Sergey Kornilov admin 8/23/2026

This option is available in PHPRunner and ASPRunner.NET:

img alt

More info:
https://xlinesoft.com/asprunnernet/docs/miscellaneous_settings.htm

J
jMullally author 8/23/2026

The 'Warn about leaving Add/Edit pages' does not work in modal popups.

There is also a problem with my solution as it only works well when clicking the popup 'X' in the top right corner. Clicking the 'Cancel' closes the popup before the JS on click fires.