.net里用了一个父窗口和子窗口传值的JS,但父页面却得不到子页面传来的值,很纳闷,报错是说window.opener.document.getElementById('父窗口控件ID名')为空或不是对象。希望高手帮指点:
父页面
<%@ Page Language="C#" MasterPageFile="~/CMSMasterPage.master" AutoEventWireup="true"
Inherits="ManageLogDataList" Title="Untitled Page" CodeBehind="ManageLogDataList.aspx.cs" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script type="text/javascript">
function showDialog() {
window.open("UserSearch.aspx");
}
</script>
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
<asp:Button ID="btnUserSearch" runat="server" Text="U"/>
</asp:Content>
父页面后台
public partial class ManageLogDataList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
btnUserSearch.Attributes.Add("onclick", "this.form.target='_blank'");
this.btnUserSearch.Attributes.Add("onclick", "showDialog()");
}
}
子页面:他是父页面点击后重新打开一个新页面,再这个页面里做了一些操作,search了一些数据,然后选定一个值,打算返回给父页面
子页后台
protected void LinkButton_Command(object sender, CommandEventArgs e)
{
string userName = (string)e.CommandArgument;//这个是我再子页面得到的值,需要传到父页的值,这个值已经得到。
Response.Write("<script type='text/JavaScript'>
window.opener.document.getElementById('<%=txtUserName.ClientID %>').value = '" + userName + "';alert(window.opener.location.href);</script>");
}
当我点击子页面上的button触发LinkButton_Command事件时,报错window.opener.document.getElementById('<%=txtUserName.ClientID %>')为空或者不是对象.
当我不清楚到底是哪地方出了问题,所以希望有此方面经验的人多多帮助,谢谢
分享到:
相关推荐
比如点击了a.htm上的一个链接而打开了b.htm,然后我们打算在b.htm上输入一个值然后赋予a.htm上的一个id为“name”的textbox中,就可以写为: window.opener.document.getElementById(“name”).value = “输入的数据...
5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID号").name(或value) 6.一个小写转大写的JS: document.getElementById("output").value = document.getElementById("input").value.toUpperCase...
代码如下: //返回值给父窗体 function returnParent(value) {//获取子窗体返回值 var parent = window.dialogArguments;... //关闭子页面 } //window.opener.document.getElementById(“ActivityPic”);
ff里不能通过对Frame的ID来直接访问 (IE FF都可以直接通过Frame的Name来访问,但是FrameSet不支持name属性) 因此window.parent.full =》window.parent.document.getElementById(“full”); js操作frame详细解说,...
31.复选按钮在JS中判断是否选中:document.forms[0].checkThis.checked (checked属性代表为是否选中返回TRUE或FALSE) 32.单选按钮组(单选按钮的名称必须相同):取单选按钮组的长度document.forms[0].groupName.length ...
调用父级中的 aaa的函数 子页面中: onclick="window.parent.frames.aaa()" 父页面中: function aaa() { alert(...window.frames[0].document.getElementById(‘xx'); 可以这样 window.f
Response.Write("[removed]alert('更新成功!')[removed]"); Response.Write("[removed]window.close();[removed]"); Response.Write("[removed] ... document.getElementById("TclButton1").click(); }
var values = window.parent.opener.document.getElementById(id + “txt_dept_name”).value; var keys = window.parent.opener.document.getElementById(id + “hf_ids”).value; var ary = checkid.value.split...
document.getElementById(id); 定时 timer=setInterval("scrollwindow()",delay); clearInterval(timer); UNCODE编码 escape() ,unescape 父对象 obj.parentElement(dhtml) obj.parentNode(dom) 交换表的...
预览</a> 2、子页面,也就是a.html获取父页面中文本框的value 代码如下: $(function(){ console.info(window.opener.document.getElementById(“name”).value); }); 这样控制台中出来的则是父页面文本框的值 Don’...
tips[29] = '风险管理对网站非常重要,那些可以预测的闪失往往会造成毁灭性的打击,以史为鉴。'; tips[30] = '别总是强迫他们按照你的思维进行访问,设置“取消”功能往往能够更赢得他们的好感,给用户退路等于给...
+ '\n' +' var oFormSQL = window.opener.getObjByID("formSQL");' + '\n' +' oFormSQL.sSqlString.value = sSqlString;' + '\n' +' oFormSQL.sOper.value = "Design";' + '\n' +' if(!confirm("确认要添加新列...
搜索吧也很早就实现了这个功能,但最近在做一个项目时,发现有些需要刷新才能看到结果,自己摸索了下,其实解决方法很简单,看如下代码: function runCode(cod1) { cod=document.getElementById(cod1) ...
精确查找某个ID的元素:document.getElementById(id名); 9.null和undefined: |--null:一个特殊的值,表示“无值”--空对象。数据类型为Object |--undefined:表示声明了变量但从未赋值或者对象属性不存在 10...