js 调用iframe(在Gridvieiw 中加载的)中Button的onclick事件(100分 急!)

wenmingcool 2009-04-01 08:33:01

<asp:GridView ID="dgvPendinglist" runat="server" >
<Columns>
<asp:TemplateField HeaderText="temp" >
<ItemTemplate>
<iframe id="iframe" name="iframe" runat="server" width="700px" scrolling="no" height="100px"></iframe>
</ItemTemplate>
<ItemStyle Width="700px"></ItemStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>

这个iframe是在gridview中显示的,显示多少个iframe是不确定的。每个iframe的src是一个页面,只不过传过去的参数不同。

protected void dgvPendinglist_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow row = e.Row;
System.Web.UI.HtmlControls.HtmlGenericControl ct = (System.Web.UI.HtmlControls.HtmlGenericControl)row.Cells[2].FindControl("iframe");
ct.Attributes["src"] = "test.aspx?documentID="+row.Cells[0].Text.Trim()+"";
}
}


我想在用户点击button后,根据一些条件判断后,去调用客户端的js,js再去调用iframe中的button的onclick事件
.cs

protected void Button1_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(GetType(), "js", "<script>aaa();</script>");
}


js

function aaa()
{
//alert('');
window.frames[1].document.getElementById('Button1').onclick();
}

但是这样留言器就会报错说:'window.frames.1.document.getElementById(...)' is null or not a object

但是如果加上alert(''); 就不会报错了

function aaa()
{
alert('');
window.frames[1].document.getElementById('Button1').onclick();
}

请问是什么原因?如何解决?


...全文
341 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq2013 2009-04-01
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 huxinghuo123 的回复:]
顶下,不是很懂
[/Quote]dddd
阿非 2009-04-01
  • 打赏
  • 举报
回复
不客气 ~
zzxap 2009-04-01
  • 打赏
  • 举报
回复
window.parent.document.getElementById()
huxinghuo123 2009-04-01
  • 打赏
  • 举报
回复
顶下,不是很懂
wenmingcool 2009-04-01
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 Sandy945 的回复:]
。。。

昨天也不知道 情况是这样啊~

你iframe 页里都有什么,加载 耗时间么?

你可以人为多等一会,来确定是加载未完成 还是 别的原因
[/Quote]
谢谢阿非了!
orain 2009-04-01
  • 打赏
  • 举报
回复
楼主试试这样子来调:
var iWin = window.frames[1];
iWin.setTimeout(function(){
iWin.document.getElementById('Button1').onclick();
}, 10);
大神来了丶 2009-04-01
  • 打赏
  • 举报
回复
帮顶
wenmingcool 2009-04-01
  • 打赏
  • 举报
回复
问题解决了,就是iframe加载的问题。设置一个间隔函数就可以了,先条用bbb(),然后bbb()再调用aaa()

<script language="javascript" type="text/javascript">
function aaa()
{
window.frames[0].document.getElementById('Button1').onclick();
}

function bbb()
{
setTimeout('aaa()',100);
}

</script>
小范f-li.cn 2009-04-01
  • 打赏
  • 举报
回复
不明白...
mark..
阿非 2009-04-01
  • 打赏
  • 举报
回复
。。。

昨天也不知道 情况是这样啊~

你iframe 页里都有什么,加载 耗时间么?

你可以人为多等一会,来确定是加载未完成 还是 别的原因
orain 2009-04-01
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 wenmingcool 的回复:]
引用 8 楼 orain 的回复:
估计是 iframe 里的页面还没加载完毕。你在 iframe 的页面加载完成事件里调 button 的 click 事件再看看

我如何判断它已经加载完毕?
[/Quote]
IE 下有个 readyState,如果返回值为 "complete" 表示已经加载完毕,firefox 就不知道了。
wenmingcool 2009-04-01
  • 打赏
  • 举报
回复
up
wenmingcool 2009-04-01
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 orain 的回复:]
估计是 iframe 里的页面还没加载完毕。你在 iframe 的页面加载完成事件里调 button 的 click 事件再看看
[/Quote]
我如何判断它已经加载完毕?
copico 2009-04-01
  • 打赏
  • 举报
回复
window.frames[1].document.getElementById('Button1').onclick();
我觉得你这句不应该这么写

frames应该是个数组
var fra = document.getElementById("iframe");
fra[1].getElementById("'Button1'").click();
orain 2009-04-01
  • 打赏
  • 举报
回复
估计是 iframe 里的页面还没加载完毕。你在 iframe 的页面加载完成事件里调 button 的 click 事件再看看
wenmingcool 2009-04-01
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 mubai007 的回复:]
加断点追一下,看看window.frames[1].document.getElementById('Button1')是否有值?
[/Quote]
问题是我如果前面加上alert(''); 就可以调用成功。不加就会失败
zjybushiren88888 2009-04-01
  • 打赏
  • 举报
回复
友情帮顶
mubai007 2009-04-01
  • 打赏
  • 举报
回复
加断点追一下,看看window.frames[1].document.getElementById('Button1')是否有值?
wenmingcool 2009-04-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 copico 的回复:]
window.frames[1].document.getElementById('Button1').onclick();
这句话很奇怪啊,你想用它来做什么呢
[/Quote]
这个是测试用的,因为我gridview中有5个iframe,所以我试着调用一个
copico 2009-04-01
  • 打赏
  • 举报
回复
window.frames[1].document.getElementById('Button1').onclick();
这句话很奇怪啊,你想用它来做什么呢
加载更多回复(2)

62,268

社区成员

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

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

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

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