gpt4 book ai didi

c# - 在没有 Ajax 的 asp.net 回发后执行 javascript 函数

转载 作者:IT王子 更新时间:2023-10-29 04:26:02 25 4
gpt4 key购买 nike

我希望在不使用 ajax 的情况下在 asp.net 回发后执行 javascript 函数。

我已经在我的 even 方法中尝试了以下方法,但没有成功:

Page.ClientScript.RegisterStartupScript(GetType(), "ShowPopup", "showCheckOutPopIn('Livraison',556);");

最佳答案

您应该使用 ScriptManager 类,因为 Page.ClientScript 属性已被弃用...

The ClientScriptManager class is new in ASP.NET 2.0 and replaces Page class methods for managing scripts that are now deprecated.
Reference: MSDN - Page.ClientScript Property

ScriptManager 的优势在于它可以与异步回发一起工作,因此如果您使用 AJAX,它将无法与 ClientScriptManager 一起工作。

您的代码如下所示:

ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "showCheckOutPopIn('Livraison',556);", true);

另请注意,如果您正在使用 AJAX 并且有一段 javascript 代码,您希望在多个回传中执行,那么您应该在第一个参数中引用您的 UpdatePanel,例如:

ScriptManager.RegisterStartupScript(MainUpdatePanel, typeof(string), "ShowPopup", "showCheckOutPopIn('Livraison',556);", true);

关于c# - 在没有 Ajax 的 asp.net 回发后执行 javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/320999/

25 4 0