Dealing with “Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method.”

In the ListSearch extender I recently had a bug where you got an exception when leaving a page that had a ListBox on it, where the ListBox was the target of both a CascadingDropDown extender and a ListSearch extender.

The reason was pretty dumb– I was calling $clearHandlers(listBox) in the dispose method on the ListSearch Extender, and this was removing the handlers that the CascadingDropDown had set up.  So when the CascadingDropDown’s dispose method tried to clean up its event subscriptions, the ASP.NET AJAX runtime complained that it was not subscribed.

The solution was replace calls to $addHandlers and $clearHandlers with individual calls to $addHandler and $removeHandler for each individual event in the ListSearch’s initialize and dispose methods.

Unfortunately after implementing this solution I still got the same error … after a lot of head-scratching, it turned out to be a simple typo.  I was calling $addHandler with ‘keydown’ as the event name, and calling $removeHandler with ‘keyDown’ as the event name.

A couple of things for you to check if you get the same error.

6 thoughts on “Dealing with “Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method.”

  1. Urs Enzler

    Thanks for the info, faced the same problem with an extender of my own.

    It’s a pity because clearHandlers would be very nice to use 🙁

  2. Shashank

    I recently started using the AJAX toolkit. ListSearchExtender is 1 of the coolest in the kit. I have question, can we make some changes so that hidden div is shown and the user can actually type in the div instead of the listbox. i know that would b difficult thing for me,the way i see the code i hav lot to learn. is it possible by u to do that…

    thanks much,

  3. Brad

    Hi Damian,

    I am trying to fix the same issue in my page, although I am using the MultiHandleSliderExtender control instead of the toolkit extender you were using.

    I have 8 or 9 MultiHandleSliderExtender (to do search ranges on different datapoints), and 4 or 5 ajax combo boxes. I get the “Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method” every time the page posts back. I’ve tried both with an UpdatePanel and without one, and both give the same error.

    Do you have any additional insight as to how I might fix it? I am not manually calling any functions OnDispose of the objects as you were in your example, but thought you might have an additional suggestion.



Leave a Reply

Your email address will not be published. Required fields are marked *