Modal popup dialog window with multiple parameters

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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏码匠的流水账

聊聊pg jdbc的queryTimeout及next方法

本文主要介绍一下pg jdbc statement的queryTimeout及resultSet的next方法

3031
来自专栏PPV课数据科学社区

【学习】七天搞定SAS(六):宏的编写、程序调错

在SAS各种繁杂的PROC之后,还要来看看MACRO才可以嘛。又不能写函数... SAS中的MACRO:宏编写 MACRO主要是DO和%LET的各种组合,前者负...

3686
来自专栏跟着阿笨一起玩NET

ASP.NET 存储过程操作

存储过程是存放在数据库服务器上的预先编译好的sql语句。使用存储过程,可以直接在数据库中存储并运行功能强大的任务。存储过程在第一应用程序执行时进行语法检查和编...

1281
来自专栏码匠的流水账

聊聊spring cloud的EurekaServerInitializerConfiguration

本文主要研究一下spring cloud的EurekaServerInitializerConfiguration

1412
来自专栏分布式系统进阶

Influxdb中Select查询请求结果涉及到的一些数据结构

相当于c里面的链表元素,itr指向下一个元素的指针,buf表示当前元素,即FloatPoint类型的链表的迭代器.

1402
来自专栏木宛城主

PowerShell 获取Site Collection下被签出的文件

由于权限的设置,当文件被签出时导致别人不可见了,这对校验文件个数的人来说着实是件烦恼的事。幸好利用PowerShell,可以获取Site Collection下...

2017

.NET中的密钥加密

本教程将演示如何通过System.Security.Cryptography在.NET Framework 1.1中实现对称加密/密钥加密。

5898
来自专栏码匠的流水账

聊聊rocketmq的PushConsumerImpl

io/openmessaging/rocketmq/consumer/PushConsumerImpl.java

1662
来自专栏码匠的流水账

tomcat如何关闭response的outputStream

在写文件下载的时候,遇到了一个问题,就是这个ServletOutputStream到底要不要自己flush以及close。这里以tomcat容易为例,解读一下。

1211
来自专栏码匠的流水账

聊聊storm的CheckpointSpout

storm-2.0.0/storm-client/src/jvm/org/apache/storm/topology/TopologyBuilder.java

2296

扫码关注云+社区

领取腾讯云代金券