ScriptResourceAttribute Class


在程序集内定义要从客户端脚本文件使用的资源。Defines a resource in an assembly to be used from a client script file. 此类不能被继承。This class cannot be inherited.

public ref class ScriptResourceAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true)]
public sealed class ScriptResourceAttribute : Attribute
type ScriptResourceAttribute = class
    inherit Attribute
Public NotInheritable Class ScriptResourceAttribute
Inherits Attribute


下面的示例演示ScriptResourceAttribute了一个名为 CheckAnswer 的脚本文件的属性,该文件使用 VerificationResources 资源文件中的资源。The following example shows a ScriptResourceAttribute attribute for a script file named CheckAnswer.js that uses resources from the VerificationResources resource files. 该名称Answer用于引用这些资源。The name Answer is used to reference these resources.

[assembly: System.Web.UI.WebResource("LocalizingScriptResources.CheckAnswer.js", "application/x-javascript")]
[assembly: System.Web.UI.ScriptResource("LocalizingScriptResources.CheckAnswer.js", "LocalizingScriptResources.VerificationResources", "Answer")]
<Assembly: System.Web.UI.WebResource("LocalizingScriptResources.CheckAnswer.js", "application/x-javascript")> 
<Assembly: System.Web.UI.ScriptResource("LocalizingScriptResources.CheckAnswer.js", "LocalizingScriptResources.VerificationResources", "Answer")> 

下面的示例演示如何使用客户端脚本中的资源。The following example shows how to use the resources in client script. 资源键(CorrectIncorrect)带有Answer前缀以标识包含这些值的脚本资源定义。The resource keys (Correct and Incorrect) are prefixed with Answer to identify the script resource definition that contains the values.

function CheckAnswer()
    var firstInt = $get('firstNumber').innerText;
    var secondInt = $get('secondNumber').innerText;
    var userAnswer = $get('userAnswer');
    if ((Number.parseLocale(firstInt) + Number.parseLocale(secondInt)) == userAnswer.value)
        return true;
        return false;


ScriptResourceAttribute类仅在程序集声明中使用时才有效。The ScriptResourceAttribute class is valid only when you use it in assembly declarations. 使用它可以在程序集中启用指定的嵌入脚本资源。You use it to enable a specified embedded script resource in an assembly. 您可以定义嵌入脚本库的名称、脚本库的资源文件的名称以及用于检索资源值的脚本文件中使用的名称。You can define the name of the embedded script library, the name of the resource file for the script library, and the name that is used in a script file for retrieving the resource values. 类使用中ScriptResourceAttribute的属性为脚本库确定正确的资源名称。 ScriptManagerThe ScriptManager class uses the properties in ScriptResourceAttribute to determine the correct resource name for a script library. TypeName属性用于指定资源的资源键。The TypeName property is used with a resource key to specify a resource.


ScriptResourceAttribute类只能用于识别 JavaScript 文件的基于文本的资源。The ScriptResourceAttribute class can be used only to identify text-based resources for JavaScript files. 若要将本地化的图像(二进制)文件与特定的区域性关联,请考虑将其 URL 仅存储为本地化资源,然后在脚本中对其进行解析和加载。To associate a localized image (binary) file with a particular culture, consider storing only its URL as a localized resource, which then be resolved and loaded in script.



初始化 ScriptResourceAttribute 类的新实例。Initializes a new instance of the ScriptResourceAttribute class.

ScriptResourceAttribute(String, String, String)

初始化 ScriptResourceAttribute 类的新实例。Initializes a new instance of the ScriptResourceAttribute class.



获取脚本库的名称。Gets the name of the script library.


获取脚本库中资源文件的名称。Gets the name of the resource file for the script library.


获取要为资源文件中的值创建的客户端类型的名称。Gets the name of the client type to create for the values in the resource file.


获取脚本库中资源文件的名称。Gets the name of the resource file for the script library.


在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

获取可在检索资源文件中的值时所使用的名称。Gets the name that is used when retrieving the values in the resource file.



返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)

返回此实例的哈希代码。Returns the hash code for this instance.

(Inherited from Attribute)

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

Applies to