Skip to main content

CONFIRMATION BOX WITH YES NO BUTTONS USING AJAX MODAL POPUP EXTENDER IN ASP.NET

Here  I am explained with an example , how to built a confirmation box (confirm box) with Yes , No Buttons or Options using AJAX Control Toolkit ModalPopupExtender control Modal Popup in ASP.Net
In this article, I will explain how to use ASP.Net AJAX Control Toolkit ConfirmButtonExtender with ModalPopupExtender Modal Popup in order to style the ConfirmButtonExtender dialog and also to make it look same in all browsers.
 
By default the Confirmation Box displayed in Internet Explorer as follows
ASP.Net AJAX ConfirmButtonExtender with ModalPopupExtender Example

In the following example I will make use of a dummy Button with Confirmation Box using ConfirmButtonExtender with ModalPopupExtender Modal Popup.
HTML Markup
First we need to register the AJAX Control Toolkit on the page
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
Below is an ASP.Net Button with associated ConfirmButtonExtender and ModalPopupExtender for displaying the confirmation box.
  <asp:Button runat="server" Width="130px" Text="Book Room" ID="btnSubmit" OnClick="btnSubmit_Click"
                                            ToolTip="Click To Book Rooms" />
 <ajaxToolkit:ConfirmButtonExtender ID="cbe" runat="server" DisplayModalPopupID="mpe"
            TargetControlID="btnSubmit" ConfirmText="Are you sure you want to Book Room Now?" />
                    <ajaxToolkit:ModalPopupExtender ID="mpe" runat="server" PopupControlID="pnlPopup"
                                TargetControlID="btnSubmit" OkControlID="btnYes" CancelControlID="btnNo" BackgroundCssClass="modalBackground">
                                        </ajaxToolkit:ModalPopupExtender>
           <asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopupConfirm" Style="display: none">
                                            <div class="header">
                                                Confirmation Details
                                            </div>
                                            <div class="body">
                                         <span class="ui-icon ui-icon-alert" style="margin: 8px 8px 0px 10px; float: left;">
                                                </span>Are you sure you want to Book Room(s) now ?
                                            </div>
                                            <div class="footer" align="right">
                                                <asp:Button ID="btnYes" runat="server" Text="Yes" />
                                                <asp:Button ID="btnNo" runat="server" Text="No" />
                                            </div>
                                        </asp:Panel> 
In order to associate a ConfirmButtonExtender with ModalPopupExtender we need to set the following properties
1. TargetControlID – The TargetControlID of both the ConfirmButtonExtender with ModalPopupExtender must be equal.
2. DisplayModalPopupID – The DisplayModalPopupID property of the ConfirmButtonExtender must be set with the ID ModalPopupExtender Modal Popup that we need to display as Confirmation Box.
3. OkControlID and CancelControlID – Since we want the ModalPopupExtender Modal Popup to work as Confirmation Box, it is necessary that we have two buttons one for OK and one for Cancel.
The above three points are necessary so that when the Target Control of the ConfirmButtonExtender is triggered the ModalPopupExtender Modal Popup is displayed.
For more details on using the ASP.Net AJAX ModalPopupExtender please refer article Building Modal Popup using ASP.Net AJAX ModalPopupExtender Control
 
 Model PopUp Style :
<style type="text/css">
        .modalPopupConfirm
        {
            background-color: #FFFFFF;
            width: 300px;
            border: 3px solid #0DA9D0;
        }
        .modalPopupConfirm .header
        {
            background-color: #2FBDF1;
            height: 30px;
            color: White;
            line-height: 30px;
            text-align: center;
            font-weight: bold;
            width: 300px;
        }
        .modalPopupConfirm .body
        {
            min-height: 50px;
            line-height: 30px;
            font-weight: bold;
        }
        .modalPopupConfirm .footer
        {
            padding: 3px;
        }
        .modalPopupConfirm .yes, .modalPopup .no
        {
            height: 23px;
            color: White;
            line-height: 23px;
            text-align: center;
            font-weight: bold;
            cursor: pointer;
        }
        .modalPopupConfirm .yes
        {
            background-color: #2FBDF1;
            border: 1px solid #0DA9D0;
        }
        .modalPopupConfirm .no
        {
            background-color: #9F9F9F;
            border: 1px solid #5C5C5C;
        }
    </style>
Out Put :
I hope this will be helpful for you. I would like to have any feedback from you.  Your valuable feedback, question, or comments about this article are always welcome.


Comments

Popular posts from this blog

Asp.Net AjaxFileUpload Control With Drag Drop And Progress Bar

This Example explains how to use AjaxFileUpload Control With Drag Drop And Progress Bar Functionality In Asp.Net 2.0 3.5 4.0 C# And VB.NET. Previous Post  I was Explained about the   jQuery - Allow Alphanumeric (Alphabets & Numbers) Characters in Textbox using JavaScript  ,  Fileupload show selected file in label when file selected  ,  Check for file size with JavaScript before uploading  . May 2012 release of AjaxControlToolkit includes a new AjaxFileUpload Control  which supports Multiple File Upload, Progress Bar and Drag And Drop functionality. These new features are supported by Google Chrome version 16+, Firefox 8+ , Safari 5+ and Internet explorer 10 + , IE9 or earlier does not support this feature. To start with it, download and put latest AjaxControlToolkit.dll in Bin folder of application, Place ToolkitScriptManager  and AjaxFileUpload on the page. HTML SOURCE < asp:ToolkitScriptManager I...

View online files using the Google Docs Viewer

Use Google Docs Viewer for Document viewing within Browser I was looking for a way to let users see Microsoft Word Doc or PDF files online while using my application without leaving their browser without downloading files and then opening it to view with Word or PDF viewer . I was looking for some way out either via any PHP or Microsoft.NET libraries, did some googling on that; but later on I just got an idea that google already has all code written for me.. when I have any email attachment in PDF or DOC or DOCX google does it for me ..! Even while searching I can see PDFs by converting them in HTML. So I just googled it up and found that Google already has this ability that we can use Google Docs Viewer without any Google Account Login . YES that's true no Google Account login is required. It's damn simple and easy. Just pass document path as attachment as parameter and we are done. Google Docs Viewer gives us ability to embed PDF, DOC/DOCX, PPT, TIFF:...

How to send mail asynchronously in asp.net with MailMessage

With Microsoft.NET Framework 2.0 everything is asynchronous and we can send mail also asynchronously. This features is very useful when you send lots of bulk mails like offers , Discounts , Greetings . You don’t have to wait for response from mail server and you can do other task . By using     SmtpClient . SendAsync Method (MailMessage, Object)    you need to do  System.Net.Mail has also added asynchronous support for sending email. To send asynchronously, you need need to Wire up a SendCompleted event Create the SendCompleted event Call SmtpClient.SendAsync smtpClient.send() will initiate the sending on the main/ui  thread and would block.  smtpClient.SendAsync() will pick a thread from the .NET Thread Pool and execute the method on that thread. So your main UI will not hang or block . Let's create a simple example to send mail. For sending mail asynchronously you need to create a event handler that will notify that mail success...