gpt4 book ai didi

c# - ScriptManager.RegisterStartupScript 在事件(按钮、GridView 等)内失败

转载 作者:行者123 更新时间:2023-11-28 07:59:04 24 4
gpt4 key购买 nike

我有一个简单的 JavaScript 来提醒文本。

function AlertTest() {
alert('test');
}

我试图通过执行以下操作从代码隐藏中调用它:

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "AlertTest", "AlertTest();", true);

这很好用。但是,当我尝试在 Button_click 或 GridView1_RowCommand 等事件中调用它时,它不会被调用。关于如何解决这个问题有什么建议吗?

谢谢。

编辑:

我还尝试通过以下方式调用它:

ScriptManager.RegisterStartupScript(GridView1, GridView1.GetType(), "AlertTest", "AlertTest();", true);

最佳答案

在您的文件中检查这一点1. 脚本标签不能在调用之后

如果您使用更新面板,改变

 ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "AlertTest", "AlertTest();", true); 

ScriptManager.RegisterStartupScript(UpdatePanel1,UpdatePanel1.GetType(), "AlertTest", "AlertTest()", true);

还可以提供全功能的Server端

    var script = "alert('hELLO');";
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "AlertTest", script, true);

在这里你可以保存其他类(class)的消息

关于c# - ScriptManager.RegisterStartupScript 在事件(按钮、GridView 等)内失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25650687/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com