弹出窗口回传参数的问题?

by43644169 2007-12-07 02:39:56
主页面一个linkbutton弹出一新页面窗口,这个窗口中有一gridview,也是由linkbutton模板列组成的,希望在点击该列的某一项时可以将其值传回给主页面中的一个文本框,但每次点击后文本框里都没有变化,是何原因呢?希望大家给于指点!

子页面代码:
前台:
<asp:GridView id="ZGridView" runat="server" CssClass="Note" Width="100%" HeaderStyle-BackColor="AliceBlue" BorderColor="Thistle" BorderStyle="Ridge" AutoGenerateColumns="False" OnRowCommand="ZGridView_RowCommand" OnRowCreated="ZGridView_RowCreated" OnRowDataBound="ZGridView_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="初步诊断" >
<ItemTemplate >

<asp:LinkButton runat="server" CommandName="zd" ID = "zhenduan" Text='<%#Eval("ZDMS") %>' ></asp:LinkButton>
</ItemTemplate>
<ItemStyle Height="30px" />
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="AliceBlue" />
</asp:GridView>
后台:
protected void ZGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{


e.CommandName.ToString();
LinkButton lb = new LinkButton();
if (e.CommandName == "zd")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = ZGridView.Rows[index];
lb = (LinkButton)row.Cells[0].FindControl("zhenduan");


Response.Write("<script>window.opener.document.getElementByName('bwjg').value +='"+lb.Text+"';</script>");
Response.Write("<script>window.opener.forms['qita'].submit();</script>");
Response.Write("<script>window.close();</script>");

}
}
用这种方法回传不知正确否?请高手们指点!
...全文
254 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
jeremychen001181 2007-12-07
  • 打赏
  • 举报
回复
I advise you to excute your code seperately, in other words, put your javascript in the child page, give a try on your js code to see whether it works, if yes, that means there is a problem with your vb code.
by43644169 2007-12-07
  • 打赏
  • 举报
回复
解决了!xxiaocai正解!我只是在用id时,忽略了客户端生成的id 与自己命名的服务器端id是不同的,谢谢大家!
a20582661 2007-12-07
  • 打赏
  • 举报
回复
<%#DataBinder.Eval(Container.DataItem,'ZDMS') %> 试试
by43644169 2007-12-07
  • 打赏
  • 举报
回复
我的window.open是写在后台代码里的,不是直接放在页面上的,如下:
e.Row.Cells[1].Attributes.Add("onclick", "javascript:window.open('cbzd.aspx?jg=" + bb.Text + "','','width=400,height=300,toolbar=no,menubar=no,resizable=yes, top=200,left=1000');");

所以不太会用怎么得到window.showModalDialog的返回值,可否再详加指点一下?
by43644169 2007-12-07
  • 打赏
  • 举报
回复
Saroot,你这段代码我没太看明白,而且我用的是window.open,不是模态对话框。就算改成这种,我还是个菜鸟,不知这段代码是该写成一个函数呢?还是直接写在onclick里呢?能否再详解一下?

gagayt,你这段代码又应该是放在什么地方的呢?而且我笨,也没太看懂怎么用。望指点
gagayt 2007-12-07
  • 打赏
  • 举报
回复
opener.location=opener.location+你要传的变量就可以了
opener.location意思是调用页面的路径
踏雪听雨 2007-12-07
  • 打赏
  • 举报
回复
应该这样,弹出窗口的代码应该设定好返回代码
js代码
var rv = window.showModalDialog("Query_frame.aspx?key=" + key, "", "dialogWidth=500px;dialogHeight=230px;status=no;scroll=no;help=no");

rv就是返回的字串,你可以把rv换成TextBox的value

在弹出的窗口这样
window.returnValue='返回的字符串';window.close();
by43644169 2007-12-07
  • 打赏
  • 举报
回复
哪位好心的大侠来指点指点吧,急啊~~
by43644169 2007-12-07
  • 打赏
  • 举报
回复
楼上的高手,我试用你的方法,还是不行啊。不知是不是在onclientclick中我的写法有问题,双引还是单引的问题,
<asp:LinkButton runat="server" CommandName="zd" ID = "zhenduan" Text='<%#Eval("ZDMS") %>' OnClientClick="javascript:SetParentValue('<%#Eval('ZDMS') %>');" ></asp:LinkButton>

这里的<%#Eval('ZDMS') %>,如果用双引号,语句就被断开了,用了单引号,还是没回传。
by43644169 2007-12-07
  • 打赏
  • 举报
回复
自己顶一个先~ 不知是不是因为回传给主页面后,主页面要刷新才能显示出来呢?我把这个文本框已经放在一个updatepanel中了,如果这样可行的话,这个updatepanel的触发器应该怎么写呢?毕竟不是同一个页面内的控件啊~~~~
头大,高手们快出现吧!
xxiaocai 2007-12-07
  • 打赏
  • 举报
回复
我用这个。可以
<script language="javascript" type="text/javascript">
function SetParentValue(userid, username, department,departmentname)
{
var o = window.opener;
o.document.getElementById("ctl00_ContentPlaceHolder1_GridView1_ctl02_SysNumber").value = userid;
o.document.getElementById("ctl00_ContentPlaceHolder1_GridView1_ctl04_SysDepartment").value = departmentname;
o.document.getElementById("ctl00_ContentPlaceHolder1_GridView1_ctl05_SysDepartmentId").value = department;
o.document.getElementById("ctl00_ContentPlaceHolder1_txtUser").value = userid;
o.document.getElementById("ctl00_ContentPlaceHolder1_txtDepartmentID").value = departmentname;
o.document.getElementById("ctl00_ContentPlaceHolder1_txtDepartmentName").value = department;
window.close();
}
</script>

<asp:GridView ID="GridView1" runat="server" BorderWidth="0px" CellPadding="4" CellSpacing="1" CssClass="list" AutoGenerateColumns="False" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="20" AllowPaging="True">
<Columns>
<asp:TemplateField HeaderText="工号">
<ItemTemplate>
<a href="javascript:SetParentValue('<%# Eval("UserName") %>', '<%# Eval("UserName") %>', '<%# Eval("Department") %>', '<%# Eval("DepartmentName") %>')"><%# Eval("UserName")%></a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RealName" HeaderText="姓名" />
<asp:BoundField DataField="Department" HeaderText="机构编号" />
<asp:BoundField DataField="DepartmentName" HeaderText="机构名称" />
</Columns>
<PagerSettings Mode="NumericFirstLast" />
<PagerStyle CssClass="pager" />
<EmptyDataTemplate>
 您搜索的工号不存在!
</EmptyDataTemplate>
</asp:GridView>

62,046

社区成员

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

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

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

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