As mentioned above, behaviors allow you to create specific
functionality that can be reused and attached to specific controls and elements
on your page.
Now, let us first take a glimpse at the prototype definition
of Sys.Component to make us more familiar with the basic functionality of Sys.Component.
Listing 1: Prototype definition for Sys.Component
Sys.Component.prototype = {
_id: null,
_idSet: false,
_initialized: false,
_updating: false,
get_events: Sys$Component$get_events,
get_id: Sys$Component$get_id,
set_id: Sys$Component$set_id,
get_isInitialized: Sys$Component$get_isInitialized,
get_isUpdating: Sys$Component$get_isUpdating,
add_disposing: Sys$Component$add_disposing,
remove_disposing: Sys$Component$remove_disposing,
add_propertyChanged: Sys$Component$add_propertyChanged,
remove_propertyChanged: Sys$Component$remove_propertyChanged,
beginUpdate: Sys$Component$beginUpdate,
dispose: Sys$Component$dispose,
endUpdate: Sys$Component$endUpdate,
initialize: Sys$Component$initialize,
raisePropertyChanged: Sys$Component$raisePropertyChanged,
updated: Sys$Component$updated
}
Sys.Component.registerClass('Sys.Component', null, Sys.IDisposable,
Sys.INotifyPropertyChange, Sys.INotifyDisposing);
As is seen above, by deriving from the Component base class,
your custom component automatically will inherit many supported features,
including the following.
·
A cross-browser model for managing handler bindings to client
object events
·
Automatic registration of the component in the client application
as a disposable object that implements the Sys.IDisposable interface
·
Raising of notification events when properties are changed
·
Performing batch processing of component property settings, which
is more efficient in script size and processing time than handling all logic in
individual property get and set accessors
·
An override of the Sys.UI.Control.initialize method to initialize
any properties and event listeners
MS AJAX has many built-in components, such as Application,
Timer, Validator, etc. which greatly enhanced the client-side function. In the
next section, however, we are going to create our own MS AJAX client-side custom
components.