Dela via


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.

Defining Public Properties in a Custom Client Component

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;
}

Raising a PropertyChanged Event

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.

See Also

Tasks

Creating Custom Non-Visual Client Components

Concepts

Creating a Client Component Class Using the Prototype Model