Ever found yourself filling out a questionnaire form or application or profile, you just typed in what seems to be the longest questionnaire of all time to only have hit the delete button by mistake or the back button on your browser by mistake? And it prompted you with “Are you sure you want to leave this page?” If you do everything you just wrote will be lost in the internet forever.

Well if that has happened to you then you are lucky that it was using a ConfirmButton or at least a variation of it. So in short we will show you how to use AJAX ConfirmButton Extender, how to enable it and have it show a result or warning or whatever you may want to have it say.

Now that I gave you the simple user guide explanation I will also give you a reference or more semi technical explanation.

The ConfirmButton is a simple extender that catches clicks on a button and displays a message to the user. If the “OK” button is clicked, the button or link functions normally. If not, the click is trapped and the button will not perform its default submit behavior; optionally, a client script is executed if the OnClientCancel property is set. This is useful for delete links or anything else that requires confirmation from the user.

The properties in italics are optional.

  • TargetControlID – The ID of the Button control to extend.
  • ConfirmText – The confirmation text to display. HTML entities can be used, such as for a newline character.
  • OnClientCancel – The client script to execute when the Cancel button is clicked in the confirm dialog box.
  • ConfirmOnFormSubmit – true if the confirm dialog box should not be displayed until just before the form is submitted. This is useful if the page contains ASP.NET validator controls and the confirm dialog box should be displayed only after all validation checks pass.
  • DisplayModalPopupID – Specifies the ID of a ModalPopup control to use to display the confirm dialog box instead of the default window.confirm window. When you use the DisplayModalPopupID property, the following conditions must be met:
  • The ModalPopup control must be configured with the same TargetControlID value as the ConfirmButton extender. (It will work properly if the ConfirmButton extender is disabled.)
  • The ModalPopup control must specify the OkControlID or the CancelControlID properties in order to identify the buttons that correspond to the the OK and Cancel buttons in the confirm dialog box.
  • The ModalPopup must not specify a OnOkScript or OnCancelScript property.
  • ConfirmButton Client Reference
    Sys.Extended.UI.ConfirmButtonBehavior Class
    Events

    • showing(handler) – Adds or removes an event handler for the showing event.
    • Parameters – A function that represents the event handler.
    • hidden(handler) – Adds or removes an event handler for the hidden event.
    • Parameters – A function that represents the event handler.

    Methods

    • initialize() – Initializes the ConfirmButton behavior.
    • dipose() – Disposes the ConfirmButton behavior.
    • raiseShowing(eventArgs) – Raises the showing event.
    • Parameters – A Sys.EventArgs object that represents event arguments for the showing event.
    • raiseHidden(eventArgs) – Raises the hidden event.
    • Parameters – A Sys.EventArgs object that represents event arguments for the hidden event.

    Properties

    • OnClientCancel – Gets or sets a string that contains client script that executes when the Cancel button is clicked in the confirm dialog box.
    • ConfirmText – Gets or sets the confirmation text to display.
    • Remarks – HTML entities can be used, such as for a newline character.
    • ConfirmOnFormSubmit – Gets or sets a Boolean value that specifies that the confirm dialog box should not be displayed until just before the form is submitted. This is useful if the page contains ASP.NET validator controls and the confirm dialog box should be displayed only after all validation checks pass.
    • displayModalPopupID – Gets or sets a string that contains the ID of a ModalPopupBehavior control to use instead of the default window.confirm dialog box.
    • postBackScript – Gets or sets a string that contains script to run in order to initiate a postback.
    • Sys.Extended.UI.ConfirmButtonHiddenEventArgs Class

    • Summary – Defines arguments for the hidden event.
    • Parameters – Boolean confirmed
    • Properties

    • confirmed – Gets a Boolean value that indicates whether the user clicked OK.
    • Download Source Files