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.
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>
8. Supply the correct URL for your Child Webform
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>
14. Run the project.
Final Note: To make the child modal to the entire desktop, you'll need to add code to the child which uses
- <body onblur="this.focus">
DeepanPosted Jul 9, 2019, 12:43 AM
Good information
Ramesh PalaniappanPosted Aug 29, 2016, 11:25 AM
Nice
Saineshwar BageriPosted Mar 22, 2014, 1:27 PM
Give snap shot
Santosh YadavPosted Apr 8, 2013, 11:51 PM
Nice article thanks
uelz santosPosted Sep 17, 2011, 11:17 AM
I just noticed that the above example only works if I remove the <form id="form1" runat="server"> in ASP.Net inline code of a webform (parent and child web forms).
hardik pateleditedPosted Jul 4, 2011, 1:55 PMEdited Jul 4, 2011, 1:56 PM
this article is written from asp alliance site. the link for it is http://aspalliance.com/1060_How_to_Popup_a_Window_Using_DIV_Layer_in_ASPNET_1x2x.3. Please try to write your own article budy.
Michael DoyonPosted Jan 20, 2011, 1:04 PM
Hello Mr. Volking, I know that these codes work perfectly with .aspx pages with HTLM document type entries. But I am making a web site project with a Master.master, a Childmaster.master and a few .aspx pages. My question is this: The buttonlink use to open the modalPanel is located on the ChildMaster.master page. This buttonLink should open the modalPanel in every page if needed to send a message or contact me by email. It works fine when click but only in the Contact.aspx page. Where would I nest these codes ; the first part would I imagine put in the ChildMaster.master but this page has no <DocTYPE HTLM PUBLIC code(wich would give an error in Debugging mode). Would I need to put script language="javascript> under the Script run at server? The second part is about the same (no HTLM DocTYPE) so where would I put the codes needed to get the modalPanel to work with every pages? Thank you Michael D.
umesh kumarPosted Sep 23, 2010, 7:39 AM
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(); __dopostback ('',''); }
Nguyen Thanh SuPosted Aug 16, 2009, 4:58 AM
dfadaf
harishPosted Aug 5, 2009, 8:59 AM
Hi too much use full. I have facing problem in ASP.net using C# application, i was open the new window from window.showModalDialog it was open properly but in this dialog box there is some button and server event there but when i click on but new again window is open that is not required i want to perform same operation on same page. Thanks Harish
cvdfv dfvdPosted May 30, 2009, 1:54 AM
sdcdcd
Evan WalterPosted Jan 4, 2009, 10:49 PM
Safari too
Camilo VaronaPosted Jan 8, 2008, 11:02 AM
Excellent code.
rocky fanPosted Nov 7, 2007, 4:17 AM
The code is great, it works perfect. But I want to find out a way to upload attachement file from child page and render the value to parent page. How do I do? Thanks. Rocky
peng mingPosted Jun 10, 2007, 10:45 PM
I'm fine
Ignacio AldazabalPosted Jan 29, 2007, 3:35 AM
This example works perfectly with Internet Explorer, but it does not with FireFox 2.0 ¿any idea why or how to fix it?