ASP.NET兩個頁面傳遞值的實現

來源:互聯網
上載者:User
建立三個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。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.