protected override void OnInit( System.EventArgs e )
{
base.OnInit( e );
string script = string.Format( @"
window.addEventListener('beforeunload', function(e) {{
confirmationMessage = $('#{0}').val();
var activeControl = document.activeElement;
if ($('#{1}').find(activeControl).length ) {{
// todo if it isn't the cancel button
// if the active control is a child of our update panel, assume we aren't navigating away
return;
}}
if ($(activeControl).parents('.modal').length) {{
// if the active control is part of a modal (for example, a confirm delete modal) assume we aren't navigating away
return;
}}
if (confirmationMessage || '' > '') {{
(e || window.event).returnValue = confirmationMessage;
return confirmationMessage;
}}
}});
", this.ClientID, this.ParentUpdatePanel().ClientID );
ScriptManager.RegisterStartupScript( this.Page, this.Page.GetType(), "ConfirmPageUnload", script, true );
}