Click here to Skip to main content
6,291,124 members and growing! (16,201 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate

Modal popup dialog window with multiple parameters

By FlashMerlot

Modal popup dialog window which passes and returns multiple parameters
C#, VB, Javascript.NET 1.0, .NET 1.1, Win2K, WinXP, Win2003, ASP, ASP.NET, Visual Studio, Dev
Posted:13 Sep 2003
Views:192,165
Bookmarked:60 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
36 votes for this article.
Popularity: 5.82 Rating: 3.74 out of 5
4 votes, 11.1%
1
4 votes, 11.1%
2
2 votes, 5.6%
3
5 votes, 13.9%
4
21 votes, 58.3%
5

Introduction

This article shows a modal popup dialog window which passes and returns multiple parameters. This sample creates parent and child webforms. The child webform is called modally by the parent passing multiple values to the child form. The child form displays the passed values allowing them to be edited and then returns the altered values back to the parent when finished. The child form is modal to only the parent form. To make the child modal to the entire desktop, see the below final note.

Scope

ASP, ASP.NET, C#, VB.NET, Visual Basic, Java

Steps

  1. Open a New Web project in Visual Studio
  2. Create two New WebForm pages named ParentWebForm and ChildWebForm
  3. Open the HTML surface for the ParentWebForm
  4. Locate the yellow line
  5. Delete all code EXCEPT the yellow line
  6. Insert the following HTML below the existing yellow line
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
        <HEAD>
            <title>Parent Webform</title>
            <script language="javascript">
    function OpenChild() 
    {
        var ParmA = retvalA.value;
        var ParmB = retvalB.value;
        var ParmC = retvalC.value;
        var MyArgs = new Array(ParmA, ParmB, ParmC);
        var WinSettings = "center:yes;resizable:no;dialogHeight:300px"
        //ALTER BELOW LINE - supply correct URL for Child Form
    
        var MyArgs = window.showModalDialog(
       "http://localhost/ModalWin/ChildWebForm.aspx", MyArgs, WinSettings);
        if (MyArgs == null)
        {
            window.alert(
              "Nothing returned from child. No changes made to input boxes")
        }
        else
        {
            retvalA.value=MyArgs[0].toString();
            retvalB.value=MyArgs[1].toString();
            retvalC.value=MyArgs[2].toString();
        }
    }
            </script>
        </HEAD>
        <body>
            <P><INPUT id="retvalA" type="text" value="AAA"></P>
            <P><INPUT id="retvalB" type="text" value="BBB"></P>
            <P><INPUT id="retvalC" type="text" value="CCC"></P>
            <P><BUTTON onclick="OpenChild()" type="button">
                    Open Child Window</BUTTON>
            </P>
        </body>
    </HTML>
  7. In the above code, locate the line saying //ALTER BELOW LINE
  8. Supply the correct URL for your ChildWebform
  9. Open the HTML surface for the ChildWebForm
  10. Locate the yellow line
  11. Delete all code EXCEPT the yellow line
  12. Insert the following HTML below the existing yellow line
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
        <HEAD>
            <TITLE>Child Webform</TITLE>
            <script language="javascript">
    function Done() {
        var ParmA = tbParamA.value;
        var ParmB = tbParamB.value;
        var ParmC = tbParamC.value;
        var MyArgs = new Array(ParmA, ParmB, ParmC);
        window.returnValue = MyArgs;
        window.close();
    }
    function doInit() {
        var ParmA = "Aparm";
        var ParmB = "Bparm";
        var ParmC = "Cparm";
        var MyArgs = new Array(ParmA, ParmB, ParmC);
        MyArgs =  window.dialogArguments;
        tbParamA.value = MyArgs[0].toString();
        tbParamB.value = MyArgs[1].toString();
        tbParamC.value = MyArgs[2].toString();
    }
            </script>
        </HEAD>
        <BODY onload="doInit()">
            <P>Param A:<INPUT id="tbParamA" TYPE="text"></P>
            <P>Param B:<INPUT ID="tbParamB" TYPE="text"></P>
            <P>Param C:<INPUT ID="tbParamC" TYPE="text"></P>
            <BUTTON onclick="Done()" type="button">OK</BUTTON>
        </BODY>
    </HTML>
    
  13. Set the project StartUp page to be the Parent Webform
  14. Run the project.

Final Note

To make the child modal to the entire desktop, you'll need add code to the child which uses <body onblur="this.focus">.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

FlashMerlot


Member

Occupation: Web Developer
Location: United States United States

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 19 of 19 (Total in Forum: 19) (Refresh)FirstPrevNext
GeneralBrowser dependent PinmemberSorin Serban23:39 18 Mar '08  
GeneralHow can i open the popup in Firefox ? PinmemberHiRoNvp1:31 20 Sep '07  
Generalhi, can i know what u meant by yellow line Pinmemberrama charan5:49 16 Jul '07  
GeneralLightweight version inchl framework available for download (free) Pinmemberinchl6:02 12 Jun '07  
GeneralDialogs in ASP.NET using server-side-blocked-calls Pinmemberinchl12:27 27 Sep '06  
GeneralRe: Dialogs in ASP.NET using server-side-blocked-calls Pinmembernaga_01_raj1:31 29 Nov '06  
NewsRe: Dialogs in ASP.NET using server-side-blocked-calls Pinmemberinchl6:02 12 Jun '07  
GeneralHow do i get another form with postback in popup window PinmemberMahesh Perumal9:56 30 Jun '06  
GeneralUnicode support PinmemberNexum Bogazici21:13 22 Jan '06  
GeneralPopup dialog on FireFox & Safari PinmemberTham Nguyen22:41 5 Jun '05  
GeneralRe: Popup dialog on FireFox & Safari Pinmembermishraz20:14 16 Dec '05  
AnswerRe: Popup dialog on FireFox & Safari PinmemberB4rT453:23 18 Aug '06  
GeneralOverhere Pinmemberskjagini9:51 11 Feb '05  
Generalwho copies whom? PinsussAnonymous16:21 15 Jul '04  
GeneralRe: who copies whom? PinmemberDavid M. Kean19:03 15 Jul '04  
Generalwho sopies whom? PinsussAnonymous16:20 15 Jul '04  
GeneralOther types of arguments PinmemberRuuca2:33 26 Mar '04  
GeneralScope? Pinmemberkgrubbs12:24 17 Sep '03  
GeneralRe: Scope? PinmemberFlashMerlot5:29 18 Sep '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 13 Sep 2003
Editor: Nishant Sivakumar
Copyright 2003 by FlashMerlot
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project