SIGN UP MEMBER LOGIN:    
ARTICLE

AJAX ModalPopup Extender Control

Posted by Ankit Nandekar Articles | ASP.NET Programming April 18, 2011
This article demonstrates how to use ModalPopup Extender Control in ASP.Net using Ajax's.
Reader Level:
Download Files:
 

This article demonstrates how to use ModalPopup Extender Control in ASP.Net using Ajax's.

Note: We are assuming that you have already completed the installation of the Ajax Toolkit as well as have a basic understanding of coding.

About the control:

The ModalPopup extender allows a page to display content to the user in a "modal" manner which prevents the user from interacting with the rest of the page. The modal content can be any hierarchy of controls and is displayed above a background that can have a custom style applied to it. When displayed, only the modal content can be interacted with; clicking on the rest of the page does nothing. When the user is done interacting with the modal content, a click of an OK/Cancel control dismisses the modal content and optionally runs custom script. The custom script will typically be used to apply whatever changes were made while the modal mode was active. If a postback is required, simply allow the OK/Cancel control to postback and the page to re-render. You can also absolutely position a modal popup by setting the X and Y properties. By default it is centered on the page, however if just X or Y is specified then it is centered vertically or horizontally.

This article provides a few steps which will be easy to follow.

Step 1:

Before you can use any of the Ajax Control Toolkit controls in a page, you first need to add a ScriptManager to the page. You can drag the ScriptManager from the Visual Studio Toolbox window onto the page. The ScriptManager is located in the Ajax Control Toolkit tab under the Toolbox.

<asp:ScriptManager ID="ScriptManager1" runat="server">
 </asp:ScriptManager>

Step 2:

Drag a LinkButton Give id lnkLoginbtn

<asp:LinkButton ID="lnkLoginbtn" runat="server" >Login</asp:LinkButton>

Step 3:

Drag Panel control from Toolbox.Design a Login form in it.

<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none"  >

            <table style="width: 270px">
                <tr>
                    <td align="right">
                        <asp:Label ID="lblUsername" runat="server" Height="30px" Text="UserName :"></asp:Label>
                    </td>
                    <td style="width: 179px" >
    <asp:TextBox ID="txtUsername" runat="server" Width="100px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 30% " align="right">
                        <asp:Label ID="lblPassword" runat="server" Height="30px" Text="Password :"></asp:Label>
                    </td>
                    <td style="width: 179px">
                        <asp:TextBox ID="txtPassword" runat="server" Width="100px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td >
                    </td>
                    <td>
                        &nbsp; &nbsp; &nbsp;
                        <asp:Button ID="btnCancel" runat="server" Text="Cancel"  />
                        <asp:Button ID="btnLogin" runat="server" Text="LogIn" OnClick="btnLogin_Click" /></td>
                </tr>
            </table>
      
    </asp:Panel>

Step 4:

Drag ModalPopup Extender Control from Ajax toolkits provide give

             TargetControlID="lnkLoginbtn"
             PopupControlID="Panel1"
             BackgroundCssClass="modalBackground"
             DropShadow="true"
             OkControlID="btnLogin"
             OnOkScript="ok()"
             CancelControlID="btnCancel"
 
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtenderLogin" runat="server"
             TargetControlID="lnkLoginbtn"
             PopupControlID="Panel1"
             BackgroundCssClass="modalBackground"
             DropShadow="true"
             OkControlID="btnLogin"
             OnOkScript="ok()"
             CancelControlID="btnCancel" />

Step 5:

In cs files btnLogin Click event write user Authentication Code.

protected void btnLogin_Click(object sender, EventArgs e)
    {
       
      [User Authentication Code………..]
       
    }

Step 6:

Run Website...........

Login to add your contents and source code to this article
share this article :
post comment
 

Hi ankit this will work when the web config file is same as per you given only right. Can you tell in order to work what should i include from your web config file if i am working on a new one..

Posted by Dorababu M Jan 12, 2012

Hi Ankit. Thanks a lot for useful coding . Can u tell me how to register ajax toolkit. becoz I have Ajaxtoolkit DLL file but not working properly.

Posted by nisha dable Jun 28, 2011

bcoz when page loaded we dont want to display panel that why i wrote Style"Display:none" there.

Posted by Ankit Nandekar Apr 18, 2011

Hi Ankit Thanks for your contribution. Can I know why you are using Style="display: none" in panel.

Posted by Purushottam Rathore Apr 18, 2011
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Team Foundation Server Hosting
Become a Sponsor