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

抬头望远,低头沉思 2009-09-12 10:59:50
动态获取window.open()后的窗口中GridView中行的数据现在可以,
可是又出一个问题:
string jsString = "window.opener.document.getElementById('txtEmpId').value='" + Session["SelectEmpID"] + "';window.opener.document.getElementById('txtEmpName').value='" + Session["SelectEmpName"] + "';window.opener.document.getElementById('txtDepId').value='" + Session["SelectDepID"] + "';window.opener.document.getElementById('txtDepName').value='" + Session["SelectDepName"] + "';window.close();";
e.Row.Attributes.Add("ondblclick",jsString);

这样可以执行,在原窗口也能获取值
但是在该open窗口里的其他事件都不能调用了,比如点击查询按钮没任何反应,上面是对原窗口四个textBox控件赋值,若是只对一个textBox赋值则点击查询按钮就可以,

不知道有没有解决办法,期待大家的的回答,刚接触 .net不久


原帖:【急】动态获取window.open()后的窗口中GridView中行的数据
...全文
196 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
呵呵,谢谢大家的回复,问题解决了,是get和post 请求方法的问题

默认使用的get,四个参数放在请求头中,数据量太大了

把form 的method改为post就OK了!
红街咖啡 2009-09-13
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 yinyuan1987 的回复:]
引用 13 楼 wuyq11 的回复:
<ItemTemplate>
<tr>
<td align="center" onclick="javascript:SetValue(' <%#  Eval("Id")%>',' <%#Eval("Name")%>',' <%#Eval("DeptID")%>',' <%#Eval("DeptName")%>')" style="cursor: pointer; cursor: hand;" onmouseover="b_on(this)" onmouseout="b_off(this)"> <%#Eval("Name")%> </td>
</tr>
</ItemTemplate>
  var p_window;
      if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
          p_window = window.parent.opener;
      else
          p_window = window.parent.opener;


      function b_on(target) {
          color = "lightblue";
          target.style.borderColor = "black";
          target.style.backgroundColor = color;
          target.style.color = "white";

      }
      function b_off(target) {
          target.style.backgroundColor = "";
          target.style.borderColor = "";
          target.style.color = "";
          target.style.fontWeight = "";
      }
      function SetValue(id, name, deptid,deptname) {
          p_window.document.getElementById("txtEmpId").value = id;
          p_window.document.getElementById("txtEmpName").value =name;
          p_window.document.getElementById("txtDeptId").value = deptid;
          p_window.document.getElementById("txtDeptName").value = deptname;
          self.close();
      }

谢谢wuyq11,我先试试修改代码
[/Quote]
这个确实可行。
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 wuyq11 的回复:]
<ItemTemplate>
<tr>
<td align="center" onclick="javascript:SetValue(' <%#  Eval("Id")%>',' <%#Eval("Name")%>',' <%#Eval("DeptID")%>',' <%#Eval("DeptName")%>')" style="cursor: pointer; cursor: hand;" onmouseover="b_on(this)" onmouseout="b_off(this)"> <%#Eval("Name")%> </td>
</tr>
</ItemTemplate>
  var p_window;
      if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
          p_window = window.parent.opener;
      else
          p_window = window.parent.opener;


      function b_on(target) {
          color = "lightblue";
          target.style.borderColor = "black";
          target.style.backgroundColor = color;
          target.style.color = "white";

      }
      function b_off(target) {
          target.style.backgroundColor = "";
          target.style.borderColor = "";
          target.style.color = "";
          target.style.fontWeight = "";
      }
      function SetValue(id, name, deptid,deptname) {
          p_window.document.getElementById("txtEmpId").value = id;
          p_window.document.getElementById("txtEmpName").value =name;
          p_window.document.getElementById("txtDeptId").value = deptid;
          p_window.document.getElementById("txtDeptName").value = deptname;
          self.close();
      }
[/Quote]
谢谢wuyq11,我先试试修改代码
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 wuyq11 的回复:]
imgbtnSearch_Click事件不执行,事件是否丢失
[/Quote]
是的,open出的窗口的其他事件都不执行
后台代码有事件的相关处理代码
wuyq11 2009-09-13
  • 打赏
  • 举报
回复
<ItemTemplate>
<tr>
<td align="center" onclick="javascript:SetValue('<%# Eval("Id")%>','<%#Eval("Name")%>','<%#Eval("DeptID")%>','<%#Eval("DeptName")%>')" style="cursor: pointer; cursor: hand;" onmouseover="b_on(this)" onmouseout="b_off(this)"><%#Eval("Name")%></td>
</tr>
</ItemTemplate>
var p_window;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
p_window = window.parent.opener;
else
p_window = window.parent.opener;


function b_on(target) {
color = "lightblue";
target.style.borderColor = "black";
target.style.backgroundColor = color;
target.style.color = "white";

}
function b_off(target) {
target.style.backgroundColor = "";
target.style.borderColor = "";
target.style.color = "";
target.style.fontWeight = "";
}
function SetValue(id, name, deptid,deptname) {
p_window.document.getElementById("txtEmpId").value = id;
p_window.document.getElementById("txtEmpName").value =name;
p_window.document.getElementById("txtDeptId").value = deptid;
p_window.document.getElementById("txtDeptName").value = deptname;
self.close();
}
wuyq11 2009-09-13
  • 打赏
  • 举报
回复
private BibdData()
{
string empId = txtEmpID.Text.Trim();
int depId = Convert.ToInt32(ddlDepart.SelectedValue);

DataSet ds = new DataSet();
if (empId != "" && empId != null)
{
ds = HRH_MessageEmpManager.GetHRH_MessageEmp(empId, depId);
}
else
{
ds = HRH_MessageEmpManager.GetHRH_MessageEmp(depId);
}

gvMessageEmp.DataSourceID = null;
gvMessageEmp.DataSource = ds;
gvMessageEmp.DataBind();
}
protected void imgbtnSearch_Click(object sender, ImageClickEventArgs e)
{
BindData();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData(); }
}
wuyq11 2009-09-13
  • 打赏
  • 举报
回复
imgbtnSearch_Click事件不执行,事件是否丢失
  • 打赏
  • 举报
回复
大家帮帮忙,只要能解决,再加100!
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 randomfeel 的回复:]
你的txtEmpName有没有runat=server的?
如果是服务器控件,用txtEmpName在js里找应该是找不到的,要用ClientID
[/Quote]
呵呵,现在txtEmpName都可以的获取值,就是open出来窗口的其他事件没法响应
24K純帥 2009-09-13
  • 打赏
  • 举报
回复
up
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 findcaiyzh 的回复:]
试一试这两种方法
1. 在调用方写一个script函数,由被调用方调用

调用方:
<script language="javascript">
function assignToTB(QRFNoVal, CustVal) {
var QRFNo = document.getElementById('QRFNo');
QRFNo.value = QRFNoVal;

var CustCode = document.getElementById('Customer');
CustCode.value = CustVal;
}
</script>

被调用方:
<script language="javascript">
function ReturnValue(QRFNo, CustCode)
{
self.opener.assignToTB(QRFNo, CustCode);
self.close();
return false;
}
</script>

2.在被调用方试一试下面的格式:
Function close(value)

{

window.opener.document.forms[0].TextBox1.value = value;

window.close();

}

参考:
http://forums.asp.net/p/1361735/2814234.aspx
[/Quote]
首先谢谢楼上朋友的回答

第一种方法在对我情况不适合,我是在GridView行内数据绑定里定义的,也就是在后台Code里的

第二种方法我加上了forms[0]之后,还是一样
宝_爸 2009-09-12
  • 打赏
  • 举报
回复
试一试这两种方法
1. 在调用方写一个script函数,由被调用方调用

调用方:
<script language="javascript">
function assignToTB(QRFNoVal, CustVal) {
var QRFNo = document.getElementById('QRFNo');
QRFNo.value = QRFNoVal;

var CustCode = document.getElementById('Customer');
CustCode.value = CustVal;
}
</script>

被调用方:
<script language="javascript">
function ReturnValue(QRFNo, CustCode)
{
self.opener.assignToTB(QRFNo, CustCode);
self.close();
return false;
}
</script>

2.在被调用方试一试下面的格式:
Function close(value)

{

window.opener.document.forms[0].TextBox1.value = value;

window.close();

}

参考:
http://forums.asp.net/p/1361735/2814234.aspx
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 randomfeel 的回复:]
对4个textbox赋值时,4个都获取到值,而且弹出窗口也正常关闭了吗?
[/Quote]
能获取到值,也能关闭,但是在弹出窗口的其他事件不能相应了
只对一个textBox赋值可以使用,2个以上就不可以了
randomfeel 2009-09-12
  • 打赏
  • 举报
回复
对4个textbox赋值时,4个都获取到值,而且弹出窗口也正常关闭了吗?
randomfeel 2009-09-12
  • 打赏
  • 举报
回复
你的txtEmpName有没有runat=server的?
如果是服务器控件,用txtEmpName在js里找应该是找不到的,要用ClientID
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 mngzilin 的回复:]
你把Open窗口的代码贴出来看看,我在机子上试过的,没有问题。
[/Quote]

protected void gvMessageEmp_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
//设置行颜色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='lightblue'");

//添加自定义属性,当鼠标移走时还原该行的背景色

e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

//实现双击某一行后,动态更新工资页面的信息;
Session["SelectEmpID"] = e.Row.Cells[0].Text.ToString().Trim();
Session["SelectEmpName"] = e.Row.Cells[1].Text.ToString().Trim();
Session["SelectDepID"] = e.Row.Cells[2].Text.ToString().Trim();
Session["SelectDepName"] = e.Row.Cells[3].Text.ToString().Trim();

string jsString = "window.opener.document.getElementById('txtEmpId').value='" + Session["SelectEmpID"] + "';window.opener.document.getElementById('txtEmpName').value='" + Session["SelectEmpName"] + "';window.opener.document.getElementById('txtDepId').value='" + Session["SelectDepID"] + "';window.opener.document.getElementById('txtDepName').value='" + Session["SelectDepName"] + "';window.close();";
e.Row.Attributes.Add("ondblclick", jsString);
}
}


protected void imgbtnSearch_Click(object sender, ImageClickEventArgs e)
{
string empId = txtEmpID.Text.Trim();
int depId = Convert.ToInt32(ddlDepart.SelectedValue);

DataSet ds = new DataSet();
if (empId != "" && empId != null)
{
ds = HRH_MessageEmpManager.GetHRH_MessageEmp(empId, depId);
}
else
{
ds = HRH_MessageEmpManager.GetHRH_MessageEmp(depId);
}

gvMessageEmp.DataSourceID = null;
gvMessageEmp.DataSource = ds;
gvMessageEmp.DataBind();
}


页面上就只有一个TextBox让用户输入员工编号
和一个下拉列表选择部门
还有一个查询按钮,

就是想点击查询按钮显示相应的记录
mngzilin 2009-09-12
  • 打赏
  • 举报
回复
你把Open窗口的代码贴出来看看,我在机子上试过的,没有问题。
  • 打赏
  • 举报
回复
大家帮帮忙啊,分不是问题,可以再加

62,039

社区成员

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

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

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

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