[ASP.NET AJAX Client Component] Client Component Model

A component is a building block which encapsulates some functionalites and can be reused across different applications. In ASP.NET AJAX, a client component is a special object that implements a well-defined set of interfaces. Rather than implementing required interfaces directly, you can create a component by inheriting from the “Sys.Component” class or its sub classes.  

1. Types of Components

There are 2 types of components: Visual and Nonvisual.

  • Novisual components: inherited directly from the “Sys.Component” class; does not associate with the visual elements directly
  • Visual components: inherited from the “Sys.UI.Behavior” or “Sys.UI.Control” class; associated with visual elements.

The “Behavior” and “Control” classes are derived from the “Component” class and therefore they are also components.

2. The Client Component Model

The base class of all components is “Sys.Component“. It implements 3 interfaces:

  • Sys.IDisposable
  • Sys.INotifyDisposing
  • Sys.INotifyPropertyChange

– Properties –

  • id: ID of the current Component object
  • events: gets a list of event handlers that are mapped to the current component’s events (read-only)
  • isInitialized: indicating whether the current Component object is initialized (read-only)

Note that properties need to be accessed using the “get_” and “set_”syntax.

– Methods –

  • initialize(): Initializes the current Component object
  • raisePropertyChanged(propertyName): raises the propertyChanged event for the specified property

3. Sys.IDisposable Interface

The “IDisposable” interface provides the feature to free the resources used by a component.

– Methods –

  • dispose(): releases resources held by an object

4. Sys.INotifyDisposing

The “Sys.INotifyDisposing” interface allows a component to raise an “dispose” event when the component releases its resources.

– Event –

  • add_disposing(handler)
  • remove_disposing(handler)

5. Sys.INotifyPropertyChange

The “Sys.INotifyPropertyChange” interface allows a component to raise an “propertyChanged” event when a property value changes.

– Event –

  • add_propertyChanged(handler)
  • remove_propertyChanged(handler);

6. Containers

A container is an object that holds a collection of components. The “Sys.IContainer” interface is used to implement containers.

  • addComponent(component)
  • findComponent(id)
  • getComponents(): an array of all components
  • removeComponent(component)

The “Sys.Application” class is derived from the “Sys.Component” and also implements “Sys.IContainer” interface. Therefore, the “Application” object is a nonvisual component as well as a container.

7. Behaviors and Controls

Both behaviors and controls are visual components. But they represent different features.

– Behaviors –

  • The behavior object is derived from the “Sys.UI.Behavior” class
  • Behaviors provide additional features to the target elements without changing the basic functionalities
  • Mutliple behaviors can be attached to a single element

– Controls –

  • The controller object is derived from the “Sys.UI.Control” class
  • A control acts as a new element or a wrapper element of an existing element
  • A control can be associated with only one element


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s