且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

RegisterStartupScript和执行顺序

更新时间:2023-12-05 22:58:34

从MSDN页面获取

From the MSDN page for RegisterStartupScript:

使用注册的启动脚本块 RegisterStartupScript 不保证以注册时的相同顺序输出.如果启动脚本块的顺序很重要,请使用 StringBuilder 对象以将脚本块收集到单个字符串中,然后将它们全部注册为一个启动脚本.

Startup script blocks that are registered by using RegisterStartupScript are not guaranteed to be output in the same order in which they are registered. If the order of the startup script blocks is important, use a StringBuilder object to gather the script blocks in a single string, and then register them all as a single startup script.

将脚本呈现到页面后,脚本的实际执行由浏览器处理,与 ScriptManager 控件无关.查看您发布的示例,浏览器应按照编写的顺序执行这些示例.页面上的其他内容也可以调用您的 EndScript 函数吗?另外,如果您使用任何类型的回调,那么回调完成的时间是不确定的.您能否提供每个脚本中的代码示例?

After they're rendered to the page, the actual execution of the scripts is handled by the browser, and doesn't have anything to do with the ScriptManager control. Looking at the example you have posted, the browser should execute those in the order they're written. Could your EndScript function be called by something else on the page, as well? Also, if you're using any sort of callbacks, then the timing of when the callback completes is indeterminate. Can you provide an example of the code that is in each of those scripts?