Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.








Type.registerEnum Method

Registers a class as an enumeration.


ANamespace.AnEnum.registerEnum(name, flags);



A string that represents the fully qualified name of the enumeration.


true to indicate that the enumeration is a bit field; otherwise, false.


Exception Type Condition


(Debug) name cannot be evaluated as a class.


(Debug) name can be evaluated as a class, but it is not the type of this instance.


A value of the enumeration is not an integer.


A value name of the enumeration cannot be registered because it is a reserved name.


Use the registerEnum method to register a class as an enumeration (enum). An enum is a distinct type that consists of a set of named integer constants. Each enumerator must have a value that evaluates to an integer. The value can be expressed as a hexadecimal value such as 0xFFFFFF. The value name of the enum must not be a reserved keyword or name.

If the enum is a collection of bit-field flags, specify true for the flags parameter.


Assigning additional values to new versions of an enum or changing the values of the enum members in a new version can cause problems for consumers of the enum. Enum values are often used in switch statements, and if additional elements have been added to the enum type, the test for default values can return true unexpectedly. It is important to provide guidelines on how the code should react if new elements are added to any enum types.


The following example shows how to define an enumeration and register it by using the registerEnum method.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
       <asp:ScriptManager runat="server" ID="ScriptManager1">
       <script type="text/javascript">
            // Register classes to test.

            // Define an enumeration type and register it.
            Samples.LineType = function(){};
            Samples.LineType.prototype = 
                Solid:      0,
                Wide:       1,
                Rounded:    2

            // Define an enumeration type and register it.
            Samples.Color = function(){};
            Samples.Color.prototype = 
                Red:    0xFF0000,
                Blue:   0x0000FF,
                Green:  0x00FF00,
                White:  0xFFFFFF 

            // Define an enumeration flags type and register it.
            Samples.Permissions = function(){};
            Samples.Permissions.prototype = 
                Create: 0x0, 
                Read:   0x2,
                Update: 0x4,
                Delete: 0x8
            Samples.Permissions.registerEnum("Samples.Permissions", true);

            // Output: "1".

            // Output: "16711680".

            // Output: "4".