Create three aspx files: testtransfervalue. aspx (parent page), testshowmodaldialog. aspx (test window. the subpage of the value passed by the showmodaldialog () method) and testopen. aspx (test window. the subpage of the value passed by the open () method ).
The following is the HTML Script For the aspx file of the three pages. The content of the corresponding. aspx. CS file can be modified without any modification.
This is the HTML Script of the testopen. aspx file:
<% @ Page Language = "C #" codebehind = "testopen. aspx. cs" autoeventwireup = "false" inherits = "Camus. testopen" %>
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> test open </title>
<Meta name = "generator" content = "Microsoft Visual Studio. NET 7.1">
<Meta name = "code_language" content = "C #">
<Meta name = "vs_defaultclientscript" content = "JavaScript">
<Meta name = "vs_targetschema" content = http://schemas.microsoft.com/intellisense/ie5>
<SCRIPT>
Function createreturnvalue (closewindow)
{
VaR txtreturnvalue = Document. getelementbyid ("txtreturnvalue ");
If (txtreturnvalue. value = "")
{
Window. Alert ("Enter the passed value ");
Return;
}
VaR txtopenerreturnvalue?##opener.doc ument. getelementbyid ("txtreturnvalue ");
Txtopenerreturnvalue. value = txtreturnvalue. value;
Window. Alert ("the value has been passed to the parent form ");
If (closewindow)
{
Window. Opener = NULL;
Window. Close ();
}
}
</SCRIPT>
</Head>
<Body>
<Form ID = "frmtestopen" method = "Post" runat = "server">
Returned value: <input type = "text" id = "txtreturnvalue" name = "txtreturnvalue">
<Input type = "button" value = "do not close the page and return the input value" onclick = "createreturnvalue (false);"> <br>
<Input type = "button" value = "Close the page and return the input value" onclick = "createreturnvalue (true);">
</Form>
</Body>
</Html>
This is testshowmodaldialog. HTML Script of the aspx file: <% @ page Language = "C #" codebehind = "testshowmodaldialog. aspx. CS "autoeventwireup =" false "inherits =" Camus. testshowmodaldialog "%>
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> test showmodaldialog </title>
<Meta name = "generator" content = "Microsoft Visual Studio. NET 7.1">
<Meta name = "code_language" content = "C #">
<Meta name = "vs_defaultclientscript" content = "JavaScript">
<Meta name = "vs_targetschema" content = http://schemas.microsoft.com/intellisense/ie5>
<SCRIPT>
Function createreturnvalue (closewindow)
{
VaR txtreturnvalue = Document. getelementbyid ("txtreturnvalue ");
If (txtreturnvalue. value = "")
{
Window. Alert ("Enter the returned value ");
Return;
}
Returnvalue = txtreturnvalue. value;
Window. Close ();
}
</SCRIPT>
</Head>
<Body>
<Form ID = "frmtestshowmodaldialog" method = "Post" runat = "server">
Returned value: <input type = "text" id = "txtreturnvalue" name = "txtreturnvalue">
<Input type = "button" value = "Close the page and return the input value" onclick = "createreturnvalue ();">
</Form>
</Body>
</Html>
This is testtransfervalue. HTML Script of the aspx file: <% @ page Language = "C #" codebehind = "testtransfervalue. aspx. CS "autoeventwireup =" false "inherits =" Camus. testtransfervalue "%>
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> test transfervalue </title>
<Meta name = "generator" content = "Microsoft Visual Studio. NET 7.1">
<Meta name = "code_language" content = "C #">
<Meta name = "vs_defaultclientscript" content = "JavaScript">
<Meta name = "vs_targetschema" content = http://schemas.microsoft.com/intellisense/ie5>
<SCRIPT>
Function testshowmodaldialog ()
{
VaR Rv = Window. showmodaldialog ("testshowmodaldialog. aspx", window, "dialogwidth = 400px; dialogheight = 300px ");
VaR txtreturnvalue = Document. getelementbyid ("txtreturnvalue ");
If (Rv = undefined)
{
Txtreturnvalue. value = "no return value ";
}
Else
{
Txtreturnvalue. value = RV;
}
}
Function testopen ()
{
Window. Open ("testopen. aspx", "_ blank", "Height = 300, width = 400 ");
}
</SCRIPT>
</Head>
<Body>
<Form ID = "frmtesttransfervalue" method = "Post" runat = "server">
<Input type = "text" id = "txtreturnvalue" name = "txtreturnvalue"> <br>
<Input type = "button" value = "use the window. showmodaldialog () method" onclick = "testshowmodaldialog ();"> <br>
<Input type = "button" value = "use the window. open () method" onclick = "testopen ();"> <br>
</Form>
</Body>
</Html>
Set the startup page to testtransfer. aspx.