Click here to Skip to main content
15,867,488 members
Articles / Web Development / ASP.NET

ASP.NET Popup Control Displaying as multiple nested modal popups

Rate me:
Please Sign up or sign in to vote.
4.89/5 (11 votes)
26 Apr 2013CPOL3 min read 55K   2.5K   31   4
This article describes using web modelpop extender as Windows model popup dialogbox.

Introduction

We all have used the ModalPopupExtender and know the working of this control. It displays a detail part as a model, which means we cannot interact with another part of the page except the detail part. But there is a problem in ModalPopupExtender. When we show another ModalPopupExtender on the first one, it does not hide the first ModalPopupExtender. We can still interact with the first ModalPopupExtender.

Image 1

Image No. 1. “Parent and child Dialog Box”

Here the first and second dialog boxes are active. We can access both. Sometimes it spoils the application logic.

So here I am solving this problem by a User Control named ModelPopupRelation. It sets the child model popup on the parent model popup. You can add multiple ModelPopupRelation controls to set multiple relations between model pops. We can nest many model pop controls to any level.

Example:

XML
<uc1:ModelPopupRelation ID="ModelPopupRelation1" runat="server" ParentModelPopupID="mpeFirstDialogBox"
   ChildModelPopupID="mpeSecondDialogBox" Start="false" />

Background

Before starting the ModelPopupRelation control we should clear some things related to model pop functionality.

XML
<asp:Button ID="btntargetControlOfmpeFirstDialogBox" 
   runat="Server" Text="" Style="display: none;" />
<cc1:ModalPopupExtender ID="mpeFirstDialogBox" runat="server" 
  TargetControlID = "btntargetControlOfmpeFirstDialogBox" 
  PopupControlID = "pnlFirstDialogBox" CancelControlID="btnCloseFirstDialogBox" 
  Backgrou BehaviorID="mpeFirstDialogBox">
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlFirstDialogBox" runat="server" BorderStyle="Solid" BorderWidth="1" 
             Style="width: 700px; background-color: White;  display: none; height: 400px;">
       <h1>  This is the first DialogBox</h1> 
</asp:Panel>

In the above code ModalPopupExtender is displayed when the user clicks on the button btntargetControlOfmpeFirstDialogBox or ModalPopupExtender is shown dynamically by the Show() method. The Button control btntargetControlOfmpeFirstDialogBox is required  as the TargetControlID property for the ModalPopupExtender. The Panel named pnlFirstDialogBox shows the detail part. In an HTML Page this becomes:

XML
<div id="pnlFirstDialogBox" style="left:624px; top: 27.5px; width: 35%; height: 400px; position: fixed; z-index: 10001;
  background-color: white;">[includes detail part as you specified]</div>"

The background element that prevents you from interacting with other parts of the page during model popup display looks like this in HTML:

XML
<div style="left: 0px; top: 0px; width: 1920px; height: 455px; position: fixed; z-index: 10000;"
  id="mpeFirstDialogBox_backgroundElement"
  class="ModalPoupBackgroundCssClass"></div>

ModalPopupExtender includes a property BackgroundCssClass for  this background element.

ModelPopupRelation User Control 

This control implements functionality that is not supported by ModalPopupExtender. It sets one popup on another popup control. It provides three properties as you can see in the below code.

XML
<uc1:ModelPopupRelation ID="ModelPopupRelation1" runat="server" ParentModelPopupID="mpeFirstDialogBox" 
   ChildModelPopupID="mpeSecondDialogBox" 
   Start="false" 
/>
  1. ParentModelPopupID: The id of the first  ModalPopupExtender. That shows the second model popup.
  2. ChildModelPopupID: The second model popup control.
  3. Start: By default it’s true. It allows the control to set relation between model popups.

Serverside methods:  

To implement this there are some server side method :

  1. private String GetControlClientID(String modelPopupDialogBoxID)
  2. According this function gets the Client id of the model popup. We need this id in JavaScript code (client side scripting).

  3. private Control ModalPopupExtenderControlSearch(Control
    _Control, String ModalPopupExtenderID)
  4. This function searches the model popup control into the whole page. 

You can see more detail in the attached project. Both functions are fully commented.

Client  Side Methods:

  1. function EndRequestHandler<%=FunctionUniqueName %>(sender, args)
  2. This function is called after an asynchronous postback is finished and control has been returned to the browser. This function calls CreateRelation() function. 

  3. function  CreateRelation<%=FunctionUniqueName %>(ParentModelPopupID, ChildModelPopupID)
  4. This function takes two arguments ,the client id of the parent and child model popup control. It sets the z-index of the child model popup control. That is the main logic of this User Control.

  5. function Get_PopUpContrl<%=FunctionUniqueName %>(PopupControlID)
  6. This function searches the model popup control by the help of PopupControlID.

Main Logic : 

Now I am describing the main logic of the User Control. When ModalPopupExtender is rendered, it generates the z-index.  As shown in below screen.

Image 2

Image No. 2. “Parent Dialog Box”

In this image we can see that ModalPopupExtender generates z-index : 10000 for the background control(div html control). The div html control that covers the back side controls of the model popup. This is the rendered HTML for the backgroundElement control. 

Background Element:

XML
<div style="left: 0px; top: 0px; width: 1920px; height: 455px; position: fixed; z-index: 10000;"
  id="mpeFirstDialogBox_backgroundElement"
  class="ModalPoupBackgroundCssClass"></div>

Foreground Element:

XML
<div id="pnlFirstDialogBox" style="left: 624px; top: 27.5px; width: 35%; 
   height: 400px; position: fixed; z-index: 10001; background-color: white;">
[includes detail part as you specified]
</div> 

Image 3

Image No. 3. “Parent and child Dialog Box”

As you can see in the above image (Image No. 3) that we have to make a relation of z-indexes as “N -> (N+1) -> (N+2) -> (N+3) for dialog boxes and background elements. 

Concept

At the end of the document again I want to describe the concept of this control. We have to set a series of z-index for all the dialog boxes that open in nested way. You can add your on logic to set the z-index of all the dialog boxes and there background elements. 

Image 4 

Image No. 4. “Parent and child Dialog Box” 

License

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


Written By
Software Developer
India India
I'm a software engineer living in Jaipur.I have been designing and developing business solutions for the Insurance and Education industries since 2007.I like to learn new technologies and make them easier for all.

Comments and Discussions

 
GeneralGreat idea Pin
Member 96949656-Feb-14 1:26
Member 96949656-Feb-14 1:26 
GeneralRe: Great idea Pin
Girish Nama9-Oct-14 18:58
Girish Nama9-Oct-14 18:58 
GeneralMy vote of 5 Pin
nachtigal8-Jul-13 10:10
nachtigal8-Jul-13 10:10 
This is whath I wa looking for a while. Thank's
GeneralNice Article Pin
jiteshjain17-Feb-13 19:04
jiteshjain17-Feb-13 19:04 

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

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