AJAX ConfirmButton Control Extender

by top54u.com 24 May, 2008
Spotlight.....

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 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:

    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <script language="javascript" type="text/javascript">
                function onCancel()
                {
                    var lblMsg = $get('<%=lblMessage.ClientID%>');
                    lblMsg.innerHTML = "You clicked the Cancel button of AJAX confirm.";
                }
            </script>


            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Label ID="lblMessage" runat="server"></asp:Label><br />
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
                        ErrorMessage="*"></asp:RequiredFieldValidator><br />
                    <asp:Button ID="btnConfirm" runat="server" Text="Confirm" OnClick="btnConfirm_Click" />
                    <ajaxToolkit:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="btnConfirm"
                        ConfirmText="Are you sure?&#10;You want to run the server code." OnClientCancel="onCancel" ConfirmOnFormSubmit="false">
                    </ajaxToolkit:ConfirmButtonExtender>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
    </form>

 

C# code:

 

protected void btnConfirm_Click(object sender, EventArgs e)

{

lblMessage.Text =
"You clicked the OK button of AJAX confirm";

}

Spotlight.....

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , ,

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

8/23/2008 8:59:43 PM

OUR SPONSORS[+ advertise here]
related videos.....
recent posts.....
top54u ezines.....