ConfirmButtonExtender Control In Ajax

ConfirmButtonExtender is a simple extender that catches clicks on a button (or any instance of a type derived from 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 behaviour; 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.
ConfirmButtonExtender Properties:-
1.TargetControlID: - The ID of the Button control to extend.
2. ConfirmText :- The confirmation text to display.
3. OnClientCancel: - The client script to execute when the Cancel button is clicked in the confirm dialog box.
4. 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.

5. DisplayModalPopupID: - Specifies the ID of a ModalPopupExtender 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:
Example:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ConfirmButtonExtender.aspx.cs" Inherits="ConfirmButtonExtender" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<script type='text/javascript'>
 function cancelClick()
 {
 var label = $get('Label1');
 label.innerHTML = 'You click cancel in the Confirm dialog on ' + (new Date()).localeFormat("T") + '.';
 }
 </script>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div style="text-align:center">
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Click To Open Confirm Window</asp:LinkButton>
 <asp:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="LinkButton1" ConfirmText="Are you sure you want to click the LinkButton?" OnClientCancel="cancelClick" />
 <br /> <br />
 <asp:Label ID="Label1" runat="server" />
 </div>
 </form>

Code – Behind:-
 protected void LinkButton1_Click(object sender, EventArgs e)
 {
Label1.Text = "You click Ok Button in the Confirm dialog on " + DateTime.Now.ToString("hh:mm:ss tt");
}


Output:-



No comments:

Post a Comment