在子窗口中,要用JS实现<script type='text/javascript'>top.window.location.href='/Content/ManageTopNav.aspx?catalogid=7';</script>时,由于父窗口中有updatepanel控件,所以不能刷新成功。
在后台代码中使用Response.Write("<script type='text/javascript'>top.window.location.href='/Content/ManageTopNav.aspx?catalogid=7';</script>");时,会弹出出错信息,Response.Write不能被解析。
这时,我们可以在后台使用scriptManager:
ScriptManager.RegisterStartupScript(this.UpdateButton, typeof(Button), "close", "<script type='text/javascript'>parent.$(\"#LoadButton\").click();;window.close();</script>", false);
而父页面中有updatepanel控件,如果只刷新父页面,updatepanel控件内的内容就会重新加载,但不被显示(刚进入页面时,原本设计就是不显示updatepanel中的内容,只有点击load按键时才会显示).所以我们可以模仿点击load按钮,来实现刷新页面并且修改了updatepanel中的内容。

本文介绍了解决ASP.NET中带有UpdatePanel的页面刷新难题的方法。通过使用ScriptManager RegisterStartupScript进行页面脚本注册,实现了子窗口关闭及触发父窗口特定元素(如Load按钮)的行为,以此确保UpdatePanel内容得到正确更新。

2721

被折叠的 条评论
为什么被折叠?



