我的 aspx.cs 文件上的按钮单击方法中有此行
ClientScript.RegisterStartupScript(this.GetType(),
"RefreshOpener",
"RefreshParent()",
true);
我在 aspx 文件中有此代码
function RefreshParent() {
window.opener.location.href = window.opener.location.href;
}
当我调试代码时,它来到这一行ClientScript.RegisterStartupScript(this.GetType(),
“刷新开启器”,
“刷新父级()”,
真的);
但不会去aspx文件运行JS代码。
最令人沮丧的是,我在其他一些页面上使用了相同的方法,并且它们有效,但这次却无效。
这是提到的按钮
<asp:ImageButton ID="Button_KAYDET"
runat="server"
CausesValidation="False"
ImageUrl="~/images/butonlar/kucuk/kaydet.jpg"
OnClick="Button_KAYDET_Click"
meta:resourcekey="Button_KAYDETResource1" />
有什么想法吗?
最佳答案
如果按钮放置在 UpdatePanel 内部,那么您需要使用 ScriptManager.RegisterStartupScript 方法 ( MSDN Link )。
您的代码应如下所示:
ScriptManager.RegisterStartupScript(this, this.GetType(), "RefreshOpener","RefreshParent()", true);
关于c# - JavaScript 函数不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6201559/