Bind handler to Ajax Sys.Component.propertyChanged event
"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." From http://www.asp.net/AJAX/Documentation/Live/tutorials/DefiningBindableClientComponent.aspx
Does anyone know how to bind a handler to a property cha开发者_高级运维nged event when raised from a property accessor. Looked for ages but cannot find an example anywhere showing how you would do this.
I worked this out eventually it just wasn't obvious at the time.
Sys.Component.propertyChanged event is the only event raised when any property of your Ajax object changes. When the event is raised it returns the name of the property that was changed.
To access this property we just need to pass a handler to the propertyChanged event in when creating the object:
function applicationLoadHandler(sender, args) {
// Create the DemoTimer component instance.
// Set properties and bind events.
timer = $create(Demo.Timer,
{ enabled: true, id: "demoTimer1", interval: 2000 },
{ tick: OnTick, propertyChanged: doSomethingOnIntervalUpdate }, null, null);
To find out what property has been changed call the get_propertyChanged from the event args:
function doSomethingOnIntervalUpdate(sender, args) {
alert(args.get_propertyName());
}
I couldn't find any example of a propertyChanged event being bound to on any of the asp.net ajax sites but managed to work it out from a similar usage on this webpage: http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=755#start
Maybe a no brainer but stumped me for a few hours.
精彩评论