AJAX ConfirmButton Control Extender
Introduction
ConfirmButton Control Extender of AJAX Control Toolkit provides the functionality similar to that of Javascript confirm box. In Javascript you use window.confirm method to popup a message box to confirm the action of user. When the user hits OK button of confirm box then it returns true and allows the web page to perform its postback submit action. Otherwise, if user clicks the cancel button then it returns false and stops the page to perform submit action.
AJAX Control Toolkit Examples:
You can see the live samples and examples of AJAX Control Toolkit from the following links:
AJAX ConfirmButton Extender
ConfirmButton Extender also displays the confirm box with a confirmation message and OK, Cancel button to approve the client action. ConfirmButton extender control consists of some properties that can be used to customize the ConfirmButton behavior. Following are the properties:
TargetControlID: The ID of the button or link button control that will call the ConfrimButton extender message alert with confirmation message.
ConfirmText: The text to be displayed in the confirmation box. You can use as new line feeder.
ConfirmOnFormSubmit: If false then does not execute the server code until there is any ASP.Net validation control is active on the web page.
onClientCancel: You can call the javascript client side function to perform some action.
Sample Code for AJAX ConfirmButton Extender control
HTML code
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<script language="javascript" type="text/javascript">
<![CData[
function onCancel()
{
var lblMsg = $get('<%=lblMessage.ClientID%>');
lblMsg.innerHTML = "You clicked the <b>Cancel</b> button of AJAX confirm.";
}
]]>
</script>
<asp:Label ID="Label1" runat="server" Text="Click this button to open AJAX Confirm box:" Font-Bold="true" Font-Size="16px"></asp:Label><br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnConfirm" runat="server" Text="Confirm" OnClick="btnConfirm_Click" />
<ajaxToolkit:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="btnConfirm"
ConfirmText="Are you sure?
You want to run the server code." OnClientCancel="onCancel" ConfirmOnFormSubmit="false">
</ajaxToolkit:ConfirmButtonExtender>
<asp:Label ID="lblMessage" runat="server"></asp:Label><br />
</ContentTemplate>
</asp:UpdatePanel>
C# code
protected void btnConfirm_Click(object sender, EventArgs e)
{
lblMessage.Text = "You clicked the <b>OK</b> button of AJAX confirm";
}
Output:
You can see the output of above discussed code from the following link:
Continue to next tutorial: AJAX DragPanel Control Extender to learn the functionality of DragPanel extender.
