gpt4 book ai didi

asp.net - 高效使用 ASP.NET RegisterStartupScript 方法

转载 作者:行者123 更新时间:2023-11-30 13:43:43 24 4
gpt4 key购买 nike

当我在我的代码隐藏中加载数据时,我发现我经常想根据我的数据运行多个 javascript 函数。使用 StringBuilder 编译我的所有函数调用并一次发出 RegisterStartupScript 效率更高,或者如果我每次需要时都发出 RegisterStartupScript,性能是否相同?

最佳答案

我认为您使用 StringBuilder 的实现会更有效一些,因为您没有创建任何控件并且只在完成后注册脚本。您可能希望继续使用 StringBuilder 方法的另一个原因是注册脚本的顺序很重要。

来自 MSDN:

The script block added by the RegisterStartupScript method executes when the page finishes loading but before the page's OnLoad event is raised. The script blocks are not guaranteed to be output in the order they are registered. If the order of the script blocks is important, use a StringBuilder object to gather the scripts together in a single string, and then register them all in a single client script block.

关于asp.net - 高效使用 ASP.NET RegisterStartupScript 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/789292/

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