【急】动态获取window.open()后的窗口中GridView中行的数据

抬头望远,低头沉思 2009-09-11 03:49:17
.net是菜鸟一个,这个问题一直没有解决,希望得到大家的帮助,分不是问题,只要能解决,必重谢!

现在我是在一个页面中使用了window.open()打开了一个新的窗口,

新窗口的页面中有一个GridView控件来显示数据,我现在想通过鼠标双击某一行数据

把该行数据的主键值动态的显示到原来窗口的一个TextBox中,不知道如何实现。

自己现在的做法是,在新窗口的后台代码中加入:


protected void gvMessageEmp_RowDataBound(object sender, GridViewRowEventArgs e)
{
Session["SelectEmpID"] = e.Row.Cells[0].Text.ToString().Trim();

e.Row.Attributes.Add("ondblclick", "window.location.href='MessageEmp.aspx?empID=" + Session["SelectEmpID"] + "'");//这里MessageEmp.aspx就是新窗口页面,这里只是双击能把值保存到session中
}


在原来的窗口使用ajax获取session里的值,并把值赋予textBox内,但是ajax不怎么用过,一直达不到预期效果

<script language="javascript" type="text/javascript">
var empID;
empID="<%=Session["SelectEmpID"]%>";

function ajaxRead(empID){
var xmlObj = null;
if(window.XMLHttpRequest){
xmlObj = new XMLHttpRequest();
}
else if(window.ActiveXObject){
xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
}
else {
return;
}

xmlObj.onreadystatechange = function(){

if(xmlObj.readyState == 4){
//updateObj('xmlObj', xmlObj.responseXML.getElementsByTagName('data')[0].firstChild.data);
document.getElementById("txtEmpId").value = empID ;

}
}

xmlObj.open ('GET', MessageEmp.aspx, true);

xmlObj.send ('');
}
</script>


...全文
290 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sandy945 的回复:]
HTML code<inputtype='button'value='设置父窗口的文本'onclick='window.opener..document.getElementById('txtID').value='';'/>
这句是刚加的,有些问题 改成

HTML code<inputtype='button'value='设置父窗口的文本'onclick='window.opener.document.getElementById("txtID").value="";'/>
[/Quote]
谢谢2,3楼朋友,解决了
randomfeel 2009-09-11
  • 打赏
  • 举报
回复
当然有关系啊, window.open出来的页面可以通过 window.opener找到父页面的
cyrix_wxm 2009-09-11
  • 打赏
  • 举报
回复
这个东西不能这么做啊
open出来的页面 和前画面没有任何关系的啊
除非你是模态窗口

阿非 2009-09-11
  • 打赏
  • 举报
回复

<input type='button' value='设置父窗口的文本'
onclick='window.opener..document.getElementById('txtID').value='';' />

这句是刚加的,有些问题 改成


<input type='button' value='设置父窗口的文本'
onclick='window.opener.document.getElementById("txtID").value="";' />

阿非 2009-09-11
  • 打赏
  • 举报
回复
之前写的一个DEMO ,意思是一样的

a.html

<html>

<body>
要传的值
<input type='text' id='txtID' name='txtName' value='aa' /> <br>
<input type='button' value='open' onclick="window.open('b.html');" />

<script>
function method()
{
alert('a.html');
}
</script>
</body>
</html>

b.html

<html>
<script>
function getValue()
{
//document.getElementById('txt').value=window.opener.txtName.value;
document.getElementById('txt').value=window.opener.document.getElementById

('txtID').value;
}
</script>
<body onload='getValue();'>
传过来的值是
<input type='text' id='txt' />
<input type='button' value='调用父窗口的方法' onclick='window.opener.method();' />
<input type='button' value='设置父窗口的文本'
onclick='window.opener..document.getElementById('txtID').value='';' />
</body>
</html>
randomfeel 2009-09-11
  • 打赏
  • 举报
回复
你window.open打开新页面时,传一个参数过去,就是把那个用来存值的textbox的ClientID传过去
用字符串变量txtClientID把值存下来
然后在新窗口中添加一个事件,
e.Row.Attributes.Add("ondblclick", "window.opener.document.all."& txtClientID &".value=" & e.Row.Cells[0].Text.ToString().Trim() & ");

62,050

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧