控制

我通过在自定义控件中的 OnPreRender 末尾调用 ScriptManager.RegisterClientScriptResource 成功包含了 javascript 资源。但是,生成的脚本标记包含在自动包含的脚本标记之前,这些脚本标记定义了我的脚本所依赖的 TypeSys 等内容。我认为它们是按照包含的顺序定义的,但我不能稍后包含我的脚本。如何控制脚本标签的包含顺序?

I am successfully including a javascript resource by calling ScriptManager.RegisterClientScriptResource at the end of OnPreRender in my custom control. However, the resulting script tag is being included before the automatically included script tags that define things like Type and Sys which my script depends on. I thought they were defined in the order that they are included but I can't include my script any later then I am. How can I control the order in which the script tags are included?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

jJeQQOZ5 2024-10-05 14:51:53

包含自定义控件的父页面必须具有 ScriptManager,并确保您添加的自定义控件放置在 ScriptManager 标记之后。有时最好将 ScriptManager 标记放置在 MasterPage 中。

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
.......
<uc:YourControl ID= "YC" runat = "server" />

Your parent page that contains the custom control must have ScriptManager and make sure the custom control you add is placed after the ScriptManager Tag. Sometimes its best just to place the ScriptManager tag in the MasterPage.

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
.......
<uc:YourControl ID= "YC" runat = "server" />
寄居人 2024-10-05 14:51:53

尝试在 OnLoad 上执行此操作,而不是在 OnPreRender 上执行此操作

Try to do this on OnLoad, not on OnPreRender

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文