Ajax: Building Modal Popup using 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, 
  1. <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>   
Configuring the ASP.Net AJAX ModalPopupExtender 
  1. <form id="form1" runat="server">  
  2.     <asp:ScriptManager ID="ScriptManager1" runat="server">  
  3.     </asp:ScriptManager>  
  4.     <asp:Button ID="btnShow" runat="server" Text="Show Modal Popup" />  
  5.     <!-- ModalPopupExtender -->  
  6.     <cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panel1" TargetControlID="btnShow" CancelControlID="btnClose" BackgroundCssClass="modalBackground">  
  7.     </cc1:ModalPopupExtender>  
  8.     <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" align="center" style="display:none">  
  9.         This is an ASP.Net AJAX ModalPopupExtender Example<br />  
  10.         <asp:Button ID="btnClose" runat="server" Text="Close" />  
  11.     </asp:Panel>  
  12.     <!-- ModalPopupExtender -->  
  13. </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. 
  1. <style type="text/css">  
  2.     .modalBackground  
  3.     {  
  4.         background-color: Black;  
  5.         filter: alpha(opacity=90);  
  6.         opacity: 0.8;  
  7.     }  
  8.       
  9.     .modalPopup  
  10.     {  
  11.         background-color: #FFFFFF;  
  12.         border-width: 3px;  
  13.         border-style: solid;  
  14.         border-color: black;  
  15.         padding-top: 10px;  
  16.         padding-left: 10px;  
  17.         width: 300px;  
  18.         height: 140px;  
  19.     }  
  20. </style>