How to implement ConfirmButtonExtender Control on ASP.NET Website easily

By
Hi Friend , Today we will learn about ConfirmButtonExtender Control.This control displays a message to the user at the click event of the Button control. Here You will ask for the confirmation when the user clicks the button to fire some event.This popup will help users to correct the errors in the form if any.In this application,when you click the submit button,a message appears with the Confirmation dialog box.You can use your custom dialog box also. 
There are some properties of ConfirmButtonExtender Control as given below:-
  • TargetControlID:-It is helpful to set the ID of the Button control to which the extender control attached.
  • ConfirmText:-It sets the text that is displayed whit in the confirm dialog box.
  • DisplayModelPopupID:-It sets the ID of a ModalPopupExtender control to use as a confirm dialog box. 
  • OnClentCancel:-This specifies the client-side script that executes when the cancel button is clicked in the confirm dialog box.
  • ConfirmOnFormSubmit:- It determines,whether or not the confirm dialog box should wait when the form submits to display.
You can install Ajax Toolkit on your visual studio if is not installed.
There are some steps to implement this concepts on your asp.net web page as given below:-
Step 1:-First open your visual studio-->File-->New-->Web Site-->Select ASP.NET Empty Website-->OK -->Open Solution Explorer Window -->Add a New Items (default.aspx and default2.aspx) as shown below:-

Step 2:-Now Drag and drop ToolKitScriptManager and Button(Submit) Controls  on the page from the toolbox as shown below:-

Step 3:- Now Open Source file-->Drag and Drop ConfirmButtonExtender control in the Source code from the toolBox-->and set its properties TargetControlID ="Button1" ConfirmText ="Type text here" as given is Source code.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Welcome to MY.NET Tutorials</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <span class="style1"><strong><span class="style2">Click on Submit Button and 
        Confirm with OK Button</span></strong></span><br />
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <br />
        <br />
        <asp:TextBox ID="TextBox1" runat="server" Height="26px" Width="244px">Ramshanker Verma</asp:TextBox>
        <br />
        <asp:CheckBox ID="CheckBox1" runat="server" Text="Graduate" />
        <br />
        <asp:TextBox ID="TextBox2" runat="server" Height="26px" Width="244px">12/01/1990</asp:TextBox>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Height="70px" 
            style="font-weight: 700; font-size: large; color: #FF0066; background-color: #66CCFF" 
            Text="Submit" Width="246px" onclick="Button1_Click" />
        <asp:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" 
        TargetControlID ="Button1" ConfirmText = "Are you want to Confirm the Form ? If you confirm the
        form,you will not able to change any things in the Form.">
        </asp:ConfirmButtonExtender>
    </div>
    </form>
</body>
</html>
Step 4:- Now Double click on Submit Button and write the  C# Code as given below:-
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("default2.aspx");
    }
}

Step 5:-Now Run the Application (press F5)-->and press Submit Button-->You will see following output as shown below:-
Step 6:-Now press OK button -->You will redirect to other page(default2.aspx) as shown below:-
For More...
  1. Learn .NET Interview Questions and answers with examples
  2. Learn WPF Concepts with real life examples
  3. oops concepts in c#
  4. Learn Crystal Reports with real life examples
  5. Learn SQL Server with real life examples
  6. Learn web services with real life examples
Download Whole Attached file
      Download

0 comments:

Post a comment

Powered by Blogger.