ScriptMode 枚举

定义

指定 ScriptManagerScriptReference 对象是引用客户端脚本的调试版本还是发布版本。Specifies whether ScriptManager and ScriptReference objects refer to the debug or release version of client scripts.

public enum class ScriptMode
public enum ScriptMode
type ScriptMode = 
Public Enum ScriptMode
继承
ScriptMode

字段

Auto 0

ScriptManager 控件中,基于 Web.config 文件的应用程序级 <compilation> 元素在运行时确定要使用的客户端脚本版本,除非它已在 ScriptReference 控件的实例中重写。In the ScriptManager control, the version of client scripts to use is determined at run time based on the application-level <compilation> element of the Web.config file, unless it is overridden in an instance of the ScriptReference control. ScriptReference 控件中,当 Auto 应用于独立脚本文件时,它等效于 ReleaseIn the ScriptReference control, when applied to a standalone script file, Auto is equivalent to Release. 应用于程序集中的脚本引用时,Auto 等效于 InheritWhen applied to a script reference in an assembly, Auto is equivalent to Inherit.

Debug 2

ScriptManager 控件中,在网页上使用客户端脚本的调试版本,除非该版本在 ScriptReference 控件实例中进行了重写。In the ScriptManager control, the debug version of the client script is used on the Web page unless overridden in an instance of the ScriptReference control. ScriptReference 控件中,在网页上使用客户端脚本的调试版本。In the ScriptReference control, the debug version of the client script is used on the Web page.

Inherit 1

ScriptManager 控件中,Inherit 等效于 AutoIn the ScriptManager control, Inherit is equivalent to Auto. ScriptReference 控件中,来自 ScriptModeScriptManager 值决定要使用的客户端脚本的版本。In the ScriptReference control, the ScriptMode value from ScriptManager determines which version of the client script to use.

Release 3

ScriptManager 控件中,在网页上使用客户端脚本的发布版本,除非通过将 ScriptReference 实例的 ScriptMode 属性设置为 Debug 重写了该版本。In the ScriptManager control, the release version of the client script is used on the Web page unless overridden by setting the ScriptMode property of a ScriptReference instance to Debug. ScriptReference 控件中,在网页上使用客户端脚本的发布版本。In the ScriptReference control, the release version of the client script is used on the Web page.

示例

下面的示例演示一个页面, 其中的脚本版本以声明方式设置为在ScriptManager控件中发布, 但一个名为 CustomClient 的脚本在Name控件中以声明方式设置为 Debug。The following example shows a page where the script versions are declaratively set to Release in the ScriptManager control, but one script named CustomClient.js is declaratively set to Debug in the Name control.

<asp:ScriptManager ID="SM" runat="server" ScriptMode="Release">
    <Scripts>
        <asp:ScriptReference Path="CustomClient.js" ScriptMode="Debug" />
    </Scripts>
</asp:ScriptManager>
<asp:ScriptManager ID="SM" runat="server" ScriptMode="Release">
    <Scripts>
        <asp:ScriptReference Path="CustomClient.js" ScriptMode="Debug" />
    </Scripts>
</asp:ScriptManager>

注解

ScriptMode枚举提供用于设置要在网页上使用的客户端脚本版本的值。The ScriptMode enumeration provides values for setting the version of client script to use on a Web page. 枚举值可以应用ScriptManager.ScriptMode于属性或ScriptMode属性。The enumeration values can be applied to either the ScriptManager.ScriptMode property or to the ScriptReference.ScriptMode property. 对象在页面上设置所有脚本的版本, 除非它被ScriptReference对象重写。 ScriptManagerThe ScriptManager object sets the version for all scripts on the page unless it is overridden by a ScriptReference object. ScriptReference对象设置特定脚本的版本。The ScriptReference object sets the version for a particular script.

ScriptMode.Auto该值产生不同的结果, 具体取决于它是引用独立脚本文件还是引用嵌入为程序集中的资源的脚本文件。The ScriptMode.Auto value produces different results depending on whether it refers to a standalone script file or to a script file that is embedded as a resource in an assembly. 独立脚本文件使用ScriptReference属性进行定义。A standalone script file is defined with the ScriptReference.Path property. 必须通过NameAssembly属性访问程序集引用。An assembly reference must be accessed through the Name and Assembly properties. ScriptMode.Auto值的结果如下所示:The results for the ScriptMode.Auto value are as follows:

如果脚本的请求版本不存在, 则会引发错误。An error is thrown if the requested version of the script does not exist. 例如, 如果对名为 CustomScript 的独立脚本文件进行引用, 并且该ScriptManager.ScriptMode属性设置为ScriptMode.Debug, 但站点上不存在 CustomScript, 则会引发错误。For instance, an error is thrown if a reference is made to a standalone script file that is named CustomScript.js and the ScriptManager.ScriptMode property is set to ScriptMode.Debug, but CustomScript.debug.js does not exist on the site. 如果调试版本不存在, 对程序集中的脚本的引用将返回发布版本。References to scripts in an assembly return the release version if the debug version does not exist.

备注

当 machine.config 文件的部署元素的true属性设置为时,将在整个网站中使用客户端脚本的发布版本。retailWhen the retail attribute of the deployment element of the Machine.config file is set to true, the release versions of client scripts are used throughout the Web site. ScriptManager.ScriptModeScriptMode ScriptReference属性中的值将被忽略。The ScriptMode values in the ScriptManager.ScriptMode and ScriptReference.ScriptMode properties are ignored.

适用于