Author:
Filed Under: ASP.Net  |  AJAX Control Toolkit
Published Date: Apr 18, 2012
Views: 29199
 

Abstract: Here Mudassar Ahmed Khan has explained with an example how to build a simple Modal Popup using ASP.Net AJAX Control Toolkit ModalPopupExtender Control. He has also provided sample code for download at the end of article


Download Sample View Demo 4
In this article I will explain with an example how to build a Modal Popup ASP.Net AJAX ModalPopupExtender control.
Register the AJAX Control Toolkit
You will need to register the AJAX Control Toolkit Library by putting the following line just below the @PageDirective
 
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
 
 
Configuring the ASP.Net AJAX ModalPopupExtender
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Button ID="btnShow" runat="server" Text="Show Modal Popup" />
 
<!-- ModalPopupExtender -->
<cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panel1" TargetControlID="btnShow"
    CancelControlID="btnClose" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" align="center" style = "display:none">
    This is an ASP.Net AJAX ModalPopupExtender Example<br />
    <asp:Button ID="btnClose" runat="server" Text="Close" />
</asp:Panel>
<!-- ModalPopupExtender -->
</form>
 
 
Above you will notice a ScriptManager control, a Button btnShow which will be used to open the ASP.Net AJAX ModalPopupExtender Modal Popup. A Panel Panel1 which will be used to display the Modal Popup. The panel has a Button btnClose which is used to close the Modal Popup.
Finally we have the ModalPopupExtendermp1 for which we have set the PopupControlID to Panel1, TargetControlID to btnShow and the CancelControlID  to btnClose.
 
CSS Styles
You will need to include the following CSS classes.
<style type="text/css">
    .modalBackground
    {
        background-color: Black;
        filter: alpha(opacity=90);
        opacity: 0.8;
    }
    .modalPopup
    {
        background-color: #FFFFFF;
        border-width: 3px;
        border-style: solid;
        border-color: black;
        padding-top: 10px;
        padding-left: 10px;
        width: 300px;
        height: 140px;
    }
</style>
 
 
Demo
 
Downloads
 





Related Articles

Comments


Add Comment

You can add your comment about this article using the form below. Make sure you provide a valid email address
else you won't be notified when the author replies to your comment

Please note that all comments are moderated and will be deleted if they are
  • Not relavant to the article
  • Spam
  • Advertising campaigns or links to other sites
  • Abusive content.
Please do not post code, scripts or snippets.

Name*: Required
Email*: Required
Comment*: Required
Security code*: CaptchaInvalid Security Code