This documentation is archived and is not being maintained.

Defining Custom Component Properties and Raising PropertyChanged Events

When you create a client component class, you define the properties that you expect page developers to access. You can also raise Sys.Component.propertyChanged notification events in the set accessors for properties of your component. Page developers who use the component can bind the property notification event to their own handler to run code when the property value changes.

In ASP.NET AJAXclient components, property accessors are defined as methods of the class prototype. The accessor methods are named with get_ and set_ prefixes followed by the property name. The following example shows how to define a read-write property named interval in the class prototype.

get_interval: function() {
    return this._interval;
},
set_interval: function(value) {
    this._interval = value;
}

You can invoke the Sys.Component raisePropertyChanged method in a property set accessor to raise a propertyChanged event. Your component inherits the raisePropertyChanged method from the Sys.Component, Sys.UI.Behavior, or Sys.UI.Control base class.

The following example shows how to raise a propertyChanged event for an interval property whenever the property is set.

get_interval: function() {
    return this._interval;
},
set_interval: function(value) {
    if (this._interval !== value) {
        this._interval = value;
        this.raisePropertyChanged('interval');
    }
}

For an example of how to raise and handle a custom component's propertyChanged event, see Creating Custom Non-Visual Client Components. For more information about the raisePropertyChanged method, see Sys.Component.raisePropertyChanged Method.

Show: