ASP.NET頁面傳值,並返回子頁值至父頁

ASP.NET頁面傳值,並返回子頁值至父頁

1.父頁:

  1. <script type="text/javascript">
  2.       //1、open子窗口:用window.opener代表父窗口的window对象    (window.opener)
  3.       //2、模态子窗口:间接通过传window对象到子窗口,然后子窗口可获得父窗口的window对象   (window.dialogArguments)
  4.       //3、iframe中子页面:用window.parent代表父窗口的window对象 (window.parent)
  5.        function show(url, width, height) {
  6.           var ar = new Array();
  7.           ar = window.showModalDialog(url, window,'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;center:yes;status:no;scroll:no;help:no'); //打开模态对话框,变量ar接收返回值
  8.          
  9.           if (ar != null) {
  10.               document.form1.TextBox1.value = ar[0];
  11.               document.form1.TextBox2.value = ar[1];
  12.           }
  13.       } 
  14. </script>

<a href="javascript:show('show.aspx',500,400);">传值</a>
 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
 <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

 

2.子頁:

  1. <script type="text/javascript" language="javascript">      
  2. //子頁值傳回父頁         
  3. function setvalue() {
  4.             var arr = new Array();
  5.             arr[0] = document.getElementById("text1").value; 
  6.             arr[1] = document.getElementById("text2").value;
  7.             window.returnValue = arr;
  8.             window.close();
  9.         }
  10.         父页值 传到子页 
  11.         function getvalue() {
  12.             var arr = new Array();
  13.             //父页值 传到子页 
  14.             //arr[0] = window.opener.document.getElementById("textBox1").value; //open 
  15.             //alert(window.opener.document.getElementById("textBox1").innerHTML); 
  16.             //arr[1] = window.opener.document.getElementById("textBox2").value; 
  17.             arr[0] = window.dialogArguments.document.getElementById("textBox1").value; //模态 
  18.             arr[1] = window.dialogArguments.document.getElementById("textBox2").value;
  19.             //arr[0] = window.parent.document.getElementById("textBox1").value; 
  20.             //arr[1] = window.parent.document.getElementById("textBox2").value; 
  21.             if (arr != null) {
  22.                 document.getElementById("text1").value = arr[0];
  23.                 document.getElementById("text2").value = arr[1];
  24.             }
  25.         }
  26.     </script>
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="show.aspx.cs" Inherits="show" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5.     <title></title>
  6.     <%--<base target="_self" />--%>
  7.     <script type="text/javascript" language="javascript">
  8.         function ReturnValue(PamA, PamB) {
  9.             var my_array = new Array(PamA, PamB);
  10.             window.returnValue = my_array;
  11.             window.close();
  12.         }
  13.         
  14.         function setvalue() {
  15.             var arr = new Array();
  16.             arr[0] = document.getElementById("text1").value; 
  17.             arr[1] = document.getElementById("text2").value;
  18.             window.returnValue = arr;
  19.             window.close();
  20.         }
  21.         function getvalue() {
  22.             var arr = new Array();
  23.             //父页值 传到子页
  24.             //arr[0] = window.opener.document.getElementById("textBox1").value; //open
  25.             //alert(window.opener.document.getElementById("textBox1").innerHTML);
  26.             //arr[1] = window.opener.document.getElementById("textBox2").value;
  27.             arr[0] = window.dialogArguments.document.getElementById("textBox1").value; //模态
  28.             arr[1] = window.dialogArguments.document.getElementById("textBox2").value;
  29.             //arr[0] = window.parent.document.getElementById("textBox1").value;
  30.             //arr[1] = window.parent.document.getElementById("textBox2").value;
  31.             if (arr != null) {
  32.                 document.getElementById("text1").value = arr[0];
  33.                 document.getElementById("text2").value = arr[1];
  34.             }
  35.         }
  36.     </script>
  37. </head>
  38. <body οnlοad="getvalue();">
  39.     <form id="form1" runat="server">
  40.     <div>
  41.         <asp:TextBox ID="text1" runat="server"></asp:TextBox>
  42.         <asp:TextBox ID="text2" runat="server"></asp:TextBox>
  43.         <input id="Button1" type="button" value="Return" οnclick="setvalue();" />
  44.  <input id="Button2" type="button" value="Close" οnclick="window.close();" />
  45.     </div>
  46.     </form>
  47. </body>
  48. </html>
  • 22
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值