Implementation of transferring values between ASP. NET pages

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.