c# - RegisterClientScriptInclude : What does "type" parameter do?

标签 c# javascript asp.net server-side-includes

我目前正在调查 RegisterClientScriptInclude方法,这样我就可以确定我不会在一页上两次包含 JQuery。 Microsoft 文档指出:

This overload of the RegisterClientScriptInclude method takes key and url parameters to identify the script, as well as a type parameter to specify the identification of the client script include. You specify the type based on the object that will be accessing the resource. For instance, when using a Page instance to access the resource, you specify the Page type.

我不明白这对我到底有什么用。它是否只是以某种方式识别哪个页面/控件优先并注册包含?有人可以解释为什么除了 key /url 之外我还想提供一个类型吗?提前致谢。

最佳答案

类型与键字符串一起使用以形成唯一标识符。这用于标识包含,以便您可以使用同一脚本多次调用 RegisterClientScriptInclude,但它只会在页面中包含一次。

需要该类型,以便控件可以在页面内彼此独立地工作。如果您有两个控件使 includes 相互不了解,则它们可能会意外使用相同的键字符串。如果未使用类型(在本例中为控件的类型),一个包含将排除另一个,尽管它们从未打算相互干扰。

关于c# - RegisterClientScriptInclude : What does "type" parameter do?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7195839/

相关文章:

asp.net - 计算本季度和上季度的开始日期和结束日期

c# - String.Split 与字符串?

c# - 如何使用 SMPP 和 C# 从 SMSC 获取发送报告

c# - 如何以编程方式连接到 IIS 中托管的 WCF 服务

javascript - dblclick 不适用于触摸设备

javascript - 不要将某些 CSS 类样式应用于特定类

c# - 如何返回一个空字符串?

c# - 我可以在没有 Visual Studio 的情况下编译 DLL 吗?

javascript - 为什么在一种情况下会在 Render 上调用 onClick 函数,而在另一种情况下不会调用 onClick 函数

asp.net - 如何在 asp.net-mvc 单元测试中生成 View ?