【怪异】父窗体向子窗体传值问题

mzjmicrosoft 2009-10-19 05:03:53
前几天是子窗体向父窗体传值,已搞定,详细参见:http://topic.csdn.net/u/20091012/16/9a082f7b-97a4-4475-9d7e-b241fed6df8a.html

现在又是父窗体向子窗体传值,还是先描述下问题:
1、父窗体:
 
<ItemTemplate>
<asp:LinkButton ID="LinkButton5" runat="server" ForeColor="#000066">查看</asp:LinkButton>
<asp:Label ID="Label2" runat="server"
Text='<%#DataBinder.Eval(Container.DataItem, "F_name")%>' Visible="False" Width="0px"></asp:Label>
</ItemTemplate>



if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton l = (LinkButton)e.Row.FindControl("LinkButton5");
Label b = (Label)e.Row.FindControl("Label2");
string Temp = b.Text.ToString();
l.Attributes.Add("onclick", "window.showModalDialog('ContractParticularData.aspx?id="+Temp+"','window','dialogWidth:880px;DialogHeight=700px;status:no;help:no;resizable:yes;');window.location='#';");

}

2、子窗体:
  <tr>
<td class="style3">客户名称:</td>
<td class="style1">
<asp:Label ID="Label3" runat="server" Text="Label3"></asp:Label>
</td>
</tr>


string IDStr = Request.QueryString["id"].ToString();
OleDbConnection sqlConn = DB.CreateConn();
sqlConn.Open();
string sqlStr = "select * from XXXX where F_name='" + IDStr.ToString() + "'";

OleDbCommand MyCommand = new OleDbCommand(sqlStr, sqlConn);
OleDbDataReader MyReader = MyCommand.ExecuteReader();
while(MyReader.Read())
{
this.Label3.Text = MyReader["XXX"].ToString();
}
sqlConn.Close();


结果:子窗体数据没绑上,Label3还是显示Lable3,请问这样传值对吗?是否还有其他传值方法,还有window.showModalDialog现在用的多嘛?我的写法到底有误没?忘大侠指点迷津,小弟感谢不尽!!!
...全文
597 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
mzjmicrosoft 2009-10-19
  • 打赏
  • 举报
回复
[Quote=引用 23 楼 zhong2006 的回复:]
if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton l = (LinkButton)e.Row.FindControl("LinkButton5");
            Label b = (Label)e.Row.FindControl("Label2");
            string Temp = b.Text.ToString();
            l.Attributes.Add("onclick", "window.showModalDialog('ContractParticularData.aspx?id="+Server.UrlEncode(Temp)+"','window','dialogWidth:880px;DialogHeight=700px;status:no;help:no;resizable:yes;');window.location='#';");

        }


[/Quote]
您的正解,确实是转码问题
结贴
指间的风 2009-10-19
  • 打赏
  • 举报
回复
呵呵,当然是,你父窗体,一起传递过来了,这下你要怎么操作都可以了,没必要那么麻烦了吧。
mzjmicrosoft 2009-10-19
  • 打赏
  • 举报
回复
先下班闪人..
回家继续...
mzjmicrosoft 2009-10-19
  • 打赏
  • 举报
回复
[Quote=引用 22 楼 freesarge 的回复:]
在子窗口了打这个接受传递过来的变量,设一下断点,你就明白。
var i=window.dialogArguments;
//获得父窗口传递来的值
[/Quote]


<script type="text/javascript">
function Test()
{
var i=window.dialogArguments;
alert(i);
}
</script>

结果:竟然是window...
SK_Aqi 2009-10-19
  • 打赏
  • 举报
回复
用open试试,不要用showmodialdialog
zhong2006 2009-10-19
  • 打赏
  • 举报
回复
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton l = (LinkButton)e.Row.FindControl("LinkButton5");
Label b = (Label)e.Row.FindControl("Label2");
string Temp = b.Text.ToString();
l.Attributes.Add("onclick", "window.showModalDialog('ContractParticularData.aspx?id="+Server.UrlEncode(Temp)+"','window','dialogWidth:880px;DialogHeight=700px;status:no;help:no;resizable:yes;');window.location='#';");

}

指间的风 2009-10-19
  • 打赏
  • 举报
回复
在子窗口了打这个接受传递过来的变量,设一下断点,你就明白。
var i=window.dialogArguments;
//获得父窗口传递来的值
指间的风 2009-10-19
  • 打赏
  • 举报
回复
window 的两个点去掉
不去掉传递过去的是字符串
mzjmicrosoft 2009-10-19
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 l171147904 的回复:]
'ContractParticularData.aspx?id="+Temp+"','window','dialogWidth:880px;DialogHeight=700px;status:no;help:no;resizable:yes;');

这句话 错了!!!


id="+Temp+"',  多以一个  '


[/Quote]

额...
指间的风 2009-10-19
  • 打赏
  • 举报
回复
var i=window.dialogArguments;
//获得父窗口传递来的值
mzjmicrosoft 2009-10-19
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 cpp2017 的回复:]
注意,先删除ie 的缓存,否则你的最新的代码不会执行.

[/Quote]

详细点嘛....
l171147904 2009-10-19
  • 打赏
  • 举报
回复
'ContractParticularData.aspx?id="+Temp+"','window','dialogWidth:880px;DialogHeight=700px;status:no;help:no;resizable:yes;');

这句话 错了!!!


id="+Temp+"', 多以一个 '

cpp2017 2009-10-19
  • 打赏
  • 举报
回复
你设断点,看子窗口有没有执行到?如果没,就是缓存的问题.
mzjmicrosoft 2009-10-19
  • 打赏
  • 举报
回复
没什么惊喜
无效
指间的风 2009-10-19
  • 打赏
  • 举报
回复
是 window.showModalDialog 不是Open
mzjmicrosoft 2009-10-19
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 freesarge 的回复:]
<script type="text/javascript">
        function XuanZeContract()
        {
            window.open('子窗体.aspx','newwindow','height=300,width=500,top='+ (screen.AvailHeight-300)/2+',left='+(screen.AvailWidth-300)/2+',toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
        }


e.Row.Attributes.Add("onDblClick", "javascript:opener.location.href='父窗体.aspx?id=" + e.Row.Cells[1].Text.ToString() + "';window.close();");


注意看红色的字,这是你传递过去的参数,你可以传递 window 过去,你看看在访问这个对象,绝对会给你惊喜的。
[/Quote]

我试试你的惊喜
哈哈
mzjmicrosoft 2009-10-19
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 leonbingo 的回复:]
引用 5 楼 mzjmicrosoft 的回复:
2楼你那样过去Label3显示乱码,但说明这样可以传值


楼主,你的temp里面传递的是一个什么样的值,莫非是中文?按照你的说法是乱码
如果是中文的话你将temp变量HttpServerUtility.UrlTokenEncode一下再传,
然后再看看this.Label3.Text = Request.QueryString["id"].ToString(); 是否还是乱码
[/Quote]

中文

leonbingo 2009-10-19
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 mzjmicrosoft 的回复:]
2楼你那样过去Label3显示乱码,但说明这样可以传值
[/Quote]

楼主,你的temp里面传递的是一个什么样的值,莫非是中文?按照你的说法是乱码
如果是中文的话你将temp变量HttpServerUtility.UrlTokenEncode一下再传,
然后再看看this.Label3.Text = Request.QueryString["id"].ToString(); 是否还是乱码
指间的风 2009-10-19
  • 打赏
  • 举报
回复
<script type="text/javascript">
function XuanZeContract()
{
window.open('子窗体.aspx','newwindow','height=300,width=500,top='+ (screen.AvailHeight-300)/2+',left='+(screen.AvailWidth-300)/2+',toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
}


e.Row.Attributes.Add("onDblClick", "javascript:opener.location.href='父窗体.aspx?id=" + e.Row.Cells[1].Text.ToString() + "';window.close();");


注意看红色的字,这是你传递过去的参数,你可以传递 window 过去,你看看在访问这个对象,绝对会给你惊喜的。
cpp2017 2009-10-19
  • 打赏
  • 举报
回复
注意,先删除ie 的缓存,否则你的最新的代码不会执行.
加载更多回复(8)

62,046

社区成员

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

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

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

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