javascript页面间进行传值(弹出对话框形式)

本文介绍如何将ASP.NET页面test1.aspx中的ListBox选定值,通过弹窗方式传递到test2.aspx页面的TextBox中。利用window.showModalDialog及window.dialogArguments实现跨页面数据交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

test1.aspx页面的listbox的值,传到test2.aspx的textbox中

test1.aspx页面代码

 

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
  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.   
  7. </head>
  8. <body>
  9.     <form id="form1" runat="server">
  10.     <div>
  11.      <script type="text/javascript"
  12.         function openChild() 
  13.         { 
  14.             var k = window.showModalDialog ("../test2.aspx",window, "dialogWidth:395px;status:no;dialogHeight:495px"); 
  15.         } 
  16.     </script> 
  17.         <asp:ListBox ID="lstSjr" runat="server">
  18.             <asp:ListItem Selected="True" Value="abc"></asp:ListItem>
  19.             <asp:ListItem Value="cc"></asp:ListItem>
  20.         </asp:ListBox>
  21.   
  22.         <input id="Button2" type="button" onclick="openChild()" value="button" />
  23.     </div>
  24.         
  25.     </form>
  26. </body>
  27. </html>

test2.aspx页面代码

 

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test2.aspx.cs" Inherits="test2" %>
  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. </head>
  7. <body>
  8.     <form id="form1" runat="server">
  9.     <div>
  10.         
  11.         <input id="txtSxr" type="text" />
  12.             <script language="javascript" type="text/javascript"
  13.                 var k = window.dialogArguments;  
  14.                 document.getElementById("txtSxr").value = k.document.getElementById("lstSjr").value;   
  15.         </script> 
  16.     </div>
  17.     </form>
  18. </body>
  19. </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值