ASP.NET两个页面传递值的实现

创建三个aspx文件:TestTransferValue.aspx(父页面)、TestShowModalDialog.aspx(测试window.showModalDialog()方法传递值的子页面)和TestOpen.aspx(测试window.open()方法传递值的子页面)。
  下面是三个页面的aspx文件的HTML脚本,至于相应的.aspx.cs文件内容可以不做任何改动。
  这是TestOpen.aspx文件的HTML脚本:


<%@ 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("请输入传递值");
                                return ;
                        }
                        var txtOpenerReturnValue=window.opener.document.getElementById("txtReturnValue");
                        txtOpenerReturnValue.value=txtReturnValue.value;
                        window.alert("值已经传给父窗体");
                        if (closeWindow)
                        {
                                window.opener= null;
                                window.close();
                        }
                }
                script >
        HEAD >
        < body >
                < form id ="frmTestOpen" method ="post" runat = "server">
                                返回值: < INPUT type ="text" id ="txtReturnValue" name = "txtReturnValue">
                                < INPUT type ="button" value ="不关闭页面并返回输入的值" onclick = "CreateReturnValue(false);"> < br >
                                < INPUT type ="button" value ="关闭页面并返回输入的值" onclick = "CreateReturnValue(true);">
                form >
        body >
HTML >


  这是TestShowModalDialog.aspx文件的HTML脚本:

<%@ 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("请输入返回值");
                                return ;
                        }
                        returnValue=txtReturnValue.value;
                        window.close();
                }
                script >
        HEAD >
        < body >
                < form id ="frmTestShowModalDialog" method ="post" runat = "server">
                                返回值: < INPUT type ="text" id ="txtReturnValue" name = "txtReturnValue"> 
                                < INPUT type ="button" value ="关闭页面并返回输入的值" onclick = "CreateReturnValue();">
                form >
        body >
HTML >


  这是TestTransferValue.aspx文件的HTML脚本:

<%@ 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="没有返回值";
                        }
                        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 ="用window.showModalDialog()方法" onclick = "TestShowModalDialog();"><br>
                               <INPUT type="button" value="用window.open()方法" onclick = "TestOpen();"><br>

                form >
        body >
HTML >


  启动页面设置成TestTransfer.aspx。

你可能感兴趣的:(asp.net)