Rock.Web.UI.Controls.ConfirmPageUnload.OnInit C# (CSharp) Method

OnInit() protected method

Raises the E:System.Web.UI.Control.Init event.
protected OnInit ( System e ) : void
e System An object that contains the event data.
return void
        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 );
        }
ConfirmPageUnload