Click here to Skip to main content
Click here to Skip to main content

Modal popup dialog window with multiple parameters

By , 13 Sep 2003
 

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
Web Developer
United States United States
Member
No Biography provided

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.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralBrowser dependentmemberSorin Serban18 Mar '08 - 22:39 
Hi Flash, nice article but unfortunatly not usefull at all, as this is IE6 centric. It does not work on IE7 nor FFx. I know this has been written in 2003 but even then there were more generic constructs that would be crossbrowser.
Added my own example here although it has not the "modal" property.
 
Cheers
QuestionHow can i open the popup in Firefox ?memberHiRoNvp20 Sep '07 - 0:31 
Hi all !
 
I tried this project and it works great but only on Internet Explorer for me. I can't open the popup with Firefox. Confused | :confused: D'Oh! | :doh:
If someone know the answer, please help me ! Smile | :)
Thanks... Wink | ;)
 
We live... We learn !

Generalhi, can i know what u meant by yellow linememberrama charan16 Jul '07 - 4:49 
hi,
thanks for article.can i know whats the yellow line means.i get error saying
'retValA' undefined.
 
thanks in advance
 
Rama Charan Prasad
 
"Be happy and Keep smiling.Thats what u want be always..Smile | :) "

GeneralLightweight version inchl framework available for download (free)memberinchl12 Jun '07 - 5:02 
We would like to inform you that the lightweight version of the inchl framework is released.
This release contains full source code and an extended ASP.NET demo application.
(please note that this version contains just a minor subset of the full version)
 
Download link: http://www.inchl.nl/lightweight
 

Product information:
 
The inchl framework is a powerfull MVC framework designed to support multiple platforms (ASP.NET and WinForms).
Key feature of the framework is its generic way of controlling the userinterface.
 
The full version of the framework will be released shortly.
 

Kind regards,
 
Stephan Smetsers
 
email: stephansmetsers@hotmail.com
web: http://www.inchl.nl
 


 
visit http://www.inchl.nl

GeneralDialogs in ASP.NET using server-side-blocked-callsmemberinchl27 Sep '06 - 11:27 
Hi,
 
I have created a true MVC-pattern for ASP.NET that allows dialogs windows in ASP.NET just like you would do when using WinForms.
I am using a technique called server-side-blocked calls (server-side AJAX).
On my website there are four demos online and also a recording of a live-coding-example (executable desktoprecording).
 
http://www.inchl.nl
 
The framework is freeware and is currently being applied in several projects.
It's real cool, please tell all your friends about it!
It has saved me a lot of developping time.
 
Kind regards,
 
Stephan Smetsers
stephansmetsers@hotmail.com
http://www.inchl.nl

 
visit http://www.inchl.nl

GeneralRe: Dialogs in ASP.NET using server-side-blocked-callsmembernaga_01_raj29 Nov '06 - 0:31 
Hi Stephen,
 
the framework was looking good(from demo on inchl.nl)Smile | :) , can i get a link to download it.
 

 
Naga

nagarajan.ml@gmail.com

NewsRe: Dialogs in ASP.NET using server-side-blocked-callsmemberinchl12 Jun '07 - 5:02 
We would like to inform you that the lightweight version of the inchl framework is released.
This release contains full source code and an extended ASP.NET demo application.
(please note that this version contains just a minor subset of the full version)
 
Download link: http://www.inchl.nl/lightweight
 

Product information:
 
The inchl framework is a powerfull MVC framework designed to support multiple platforms (ASP.NET and WinForms).
Key feature of the framework is its generic way of controlling the userinterface.
 
The full version of the framework will be released shortly.
 

Kind regards,
 
Stephan Smetsers
 
email: stephansmetsers@hotmail.com
web: http://www.inchl.nl
 


 
visit http://www.inchl.nl

QuestionHow do i get another form with postback in popup windowmemberMahesh Perumal30 Jun '06 - 8:56 
I have a requirement to have one page (compelete Sign In page) as a popup window when the user clicks 'Sign In' for another page.
 
Can you help me with a solution?
 
Thanks in advance,
Mahesh
GeneralUnicode supportmemberNexum Bogazici22 Jan '06 - 20:13 
Hello
 
It may seem irrelevant though I need to ask.
 
Does Passing parameters to a modal dialog and back to parent and so on, support unicode ? I mean, can I pass unicode characters as paramaters to modal dialog ? (Chinese chars for instance)
 
Thank you for the article. It is one of the simplest and therefore most beneficial one on CodeProject.
GeneralPopup dialog on FireFox & SafarimemberTham Nguyen5 Jun '05 - 21:41 
Hi all,
window.showModalDialog only works on IE, not on FireFox or Safari. Any body can help me how to show a popup dialog on FireFox and Safari.
 
Thanks
Tham Nguyen

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 14 Sep 2003
Article Copyright 2003 by FlashMerlot
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid