Modal popup dialog window with multiple parameters

本文介绍了一个使用ASP.NET创建模态弹出对话框窗口的示例,该窗口可以在父窗体和子窗体之间传递和返回多个参数。通过这个示例,展示了如何在两个Web表单之间进行交互。

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
    Collapse Copy Code
    <!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
    Collapse Copy Code
    <!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

转载于:https://www.cnblogs.com/neozhu/archive/2009/02/15/1391025.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值