JavaScript函数不起作用
本文关键字:不起作用 函数 JavaScript | 更新日期: 2023-09-27 17:58:04
我在aspx.cs文件上的按钮点击方法中有这一行
ClientScript.RegisterStartupScript(this.GetType(),
"RefreshOpener",
"RefreshParent()",
true);
我在aspx文件上有这个代码
function RefreshParent() {
window.opener.location.href = window.opener.location.href;
}
当我调试代码时,它会出现在ClientScript.RegisterStartupScript(this.GetType(),
"RefreshOpener",
"RefreshParent()",
true);
这一行,但不会转到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链接)。
你的代码应该看起来像:
ScriptManager.RegisterStartupScript(this, this.GetType(), "RefreshOpener","RefreshParent()", true);
Button_KAYDET
按钮是否放置在UpdatePanel
中?如果是使用ScriptManager.RegisterStartupScript method instead of the ClientScript.RegisterStartupScript