Sunday, March 11, 2012

Raising and catching events.

Hi,

I suppose that you're talking about client side objects. In this case, checkthis post on my blog.


Thank you. Yes, this was what I meant and the article is well written.

Would you mind explaining how to properly catch the events that get thrown from this class?


Hi,

in ms ajax, to handle an event raised by a component you have to subscribe with a statement like this:

myComponent.add_dummyEvent(myEventHandler);
function myEventHandler(sender, e) {// Handle the event here.}

Note that a component that exposes an event should declare a method for adding a handler (add_dummyEvent) and a method for removing a handler (remove_dummyEvent). You'll find that components follow the same naming conventions for these methods (ie add_<eventName> and remove_<eventName>).


Thanks so much. I tired it out and it worked like a charm!

Sorry for replying instead of editing (I didn't see the option to edit).

One thing to note for other readers - when catching the event, "this" is not the object that caught the event. If you are catching a child's event, you can look at sender.get_parent(). This will allow you to properly access the object that caught the event.

No comments:

Post a Comment