后台aspx.CS 中取得前台由 javascript脚本赋值的 TextBox值的问题
我由 Father.aspx 模态弹出子窗 Child.aspx ,然后,把由 父窗传过来的值,赋与 子窗中的一个 TextBox
,但是在子窗的 aspx.CS 中却取不到空上 TextBox 的值。
请看
Child.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PopKeywords.aspx.cs" Inherits="WebUI.BusinessCenter.PopKeywords" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>关键字选择</title> <link href="../css/css.css" rel="stylesheet" type="text/css" /> <base target="_self" /></head><body> <form id="form1" runat="server"> <table border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td height="40" align="center"> <asp:TextBox ID="txbChild" runat="server" Width="400px"></asp:TextBox> </td> </tr> </table></form></body></html><script type="text/javascript" language="javascript"> <!-- var k = window.dialogArguments; //获得父窗口传递来的值 if (k != null) { document.getElementById("txbChild").value = k.document.getElementById("txbFather").value; } //--> </script> using System;using System.Data;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace WebUI.BusinessCenter{ public partial class PopKeywords : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string getFatherValue = this.txbChild_getFather.Text.ToString().Trim(); //实际上,getFatherValue 取得值是空的 } }}<script type="text/javascript" language="javascript"> <!-- var k = window.dialogArguments; //获得父窗口传递来的值 if (k != null) { document.getElementById("txbChild").value = k.document.getElementById("txbFather").value; } //--> </script> <%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title> <script type="text/javascript"> function openChild(txt) { k = window.showModalDialog("Child1.aspx?txt=" + encodeURIComponent(txt.value)); } </script></head><body> <form id="form1" runat="server"> <table> <tr> <td height="30" bgcolor="#CAD2F4" align="left"> 关键字选择 </td> <td colspan="5" bgcolor="#FFFFFF" align="left"> <asp:TextBox ID="txbFather" class="inputtext" runat="server" Width="430px" onclick="openChild(this)"></asp:TextBox> </td> </tr> </table> </form></body></html>
[解决办法]