Click here to Skip to main content
Licence CPOL
First Posted 4 Mar 2008
Views 131,863
Downloads 5,334
Bookmarked 33 times

Modal Popup Extender Basics

By | 12 Apr 2008 | Article
Demonstrates how to use the Modal Popup Extender Control

Introduction

I want to take this opportunity to introduce a new useful control that can make our web applications really interactive. In this quick demonstration, I am going to show you how we can implement a modal Dialog Box using AJAX in ASP.NET. Modal Dialog Box (formally called ModalPopupExtender) is extremely essential in today’s applications, as writing JavaScript window.open() to open a pop-up or to open a separate ASP.NET page as a pop-up are sometimes very tedious, time consuming and more importantly, many times performance has to be sacrificed. A simple example can prove my point.

Steps for demonstration

  1. Create a new AjaxEnabledWebSite from the Visual Studio Project Wizard options.
  2. Add the AjaxControlToolkit.dll which is attached with this article to the reference collections of the Web Project. 
  3. In any page in your Web Application (let's say Default.aspx), add a Link Button named like "View Job Details".
  4. Add an HTML table with some static values and an OK and Cancel button. Place these controls (not the link button) inside a Panel control. 
  5. If the ScriptManager tag is not present in your form, then it should be specified inside the Form tag. 
  6. <asp:ScriptManager ID="ScriptManager1" runat="server" />  
  7. Design the page as shown below: 
  8. <formulas /></formulas />

  9. Add the following style sheet to a separate new file or the page itself. In this example, a separate file called StyleSheet.css has been created and included in the page.
  10. body, div, p, h1, h2, h3, h4, ul, li, table 
    {
        margin:0;
        padding:0;
        border:none;
    }
    
    /* Modal Pop-up */ 
    
    .modalBackground 
    {
        background-color:
        filter:alpha(opacity=70);
        opacity:0.7; 
    } 
    
    .modalPopup 
    {
        background-color:#ffffdd; 
        border-width:3px; 
        border-style:solid; 
        border-color:Gray; 
        padding:3px; 
        width:250px; 
    }
  11. In the head tag, place the following code:
  12. <link href="StyleSheet.css" rel="stylesheet" type="text/css" /> 
    
  13. Now place the following code just above the Panel control in a seprate row:
  14. <ajaxtoolkit:modalpopupextender 
        id="ModalPopupExtender" 
        runat="server" 
        backgroundcssclass="modalBackground" 
        cancelcontrolid="CancelButton" 
        dropshadow="true" 
        okcontrolid="OkButton" 
        popupcontrolid="Panel1" 
        popupdraghandlecontrolid="Panel3" 
        targetcontrolid="lbn_job_det"> 
    </ajaxtoolkit:modalpopupextender> 
    

    The CancelControlId property of the ModalPopUpExtender signifies that which control is treated as the Cancel button. By default property of this control is to close the dialog. But it can be customized using OnCancelScript attributes. You just need to use any JavaScript function to do that. There is a OnOkScript attribute as well.

  15. It’s mandatory to register the assembly (AJAXControlToolKit.dll). So the following code has to be placed after the page directive.
  16. <%@ Register Assembly="AjaxControlToolkit" 
        Namespace="AjaxControlToolkit" 
        TagPrefix="ajaxToolkit" %>  
    
  17. Now here comes the demo, just click on the "View job Details" button and see the Modal Popup.
  18. You can change the opacity, background color of the background. It’s all up to you and how you can play with style sheet to make your application more interactive.

This is a basic idea and demonstration about how to implement Modal Popup Extender in ASP.NET. The representation shows above simply demonstrates a Search window. This window contains a GridView which itself calls a web service to produce the search result. Please send your thoughts, ideas, suggestions and views.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

saanj

Software Developer (Senior)

United Kingdom United Kingdom

Member

Follow on Twitter Follow on Twitter
A SharePoint Kid playing in Kolkata, India.
 
Working with one of the leading software company and currently working with SharePoint technologies.
 
Enjoys Cricket, National & World Music.
 
Favourite band include Linkin Park, Beatles, Oasis, Match Box 20, Noori, Nirvana, Nickelback etc.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionsomething is missing Pinmembercjstg14:33 3 May '12  
GeneralMy vote of 5 Pinmemberstavrianosy4:27 11 Aug '11  
GeneralMy vote of 1 PinmemberFrank Kerrigan23:30 31 May '11  
GeneralMy vote of 3 PinmemberMaKost5:54 22 Jan '11  
GeneralImages missing PinsubeditorIndivara18:13 21 Jan '11  
GeneralOkButton PinmembergranadaCoder11:31 15 Nov '10  
GeneralModal Popup Extender Basics PinmemberPrashant.m@rupizinfotech.com0:59 24 Nov '09  
GeneralMy vote of 1 PinmemberPranav22:33 27 Nov '08  
Generalhelp from assign value to a global variable from inputed data inside a modal popup Pinmembera1t-f416:33 22 Oct '08  
AnswerRe: help from assign value to a global variable from inputed data inside a modal popup Pinmembersaanj18:11 22 Oct '08  
GeneralModalpopupextender problem Pinmembersrinivas prabhu0:12 1 Oct '08  
GeneralRe: Modalpopupextender problem Pinmembersaanj5:59 1 Oct '08  
General[Message Removed] PinmemberMojtaba Vali1:17 9 Apr '08  
GeneralFix the formatting, please! Pinmemberpsouza4micronet4:12 4 Mar '08  
The formatting in this article reduces the worthwhileness to read it. Please fix the code section so that that (1) your HTML isn't being stripped and (2) it doesn't cause the page to scroll all over.
 
Please preview your articles before submitting them.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 12 Apr 2008
Article Copyright 2008 by saanj
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid