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
- Open a New Web project in Visual Studio
- Create two New
WebForm
pages namedParentWebForm
andChildWebForm
- Open the HTML surface for the
ParentWebForm
- Locate the yellow line
- Delete all code EXCEPT the yellow line
- 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>
- In the above code, locate the line saying //ALTER BELOW LINE
- Supply the correct URL for your
ChildWebform
- Open the HTML surface for the
ChildWebForm
- Locate the yellow line
- Delete all code EXCEPT the yellow line
- 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>
- Set the project StartUp page to be the Parent Webform
- 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">.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix