Damian Mehers' Blog Android, VR and Wearables from Geneva, Switzerland.

13Aug/076

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.

Filed under: AJAX Leave a comment
Comments (6) Trackbacks (0)
  1. 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. hi,
    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. Thanks for the solution,

    I have been wildly searching a solution for this error.

  4. No luck for me on this one … 🙁

  5. 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.

    Thanks!

  6. Hi Brad,

    I’m afraid I’m not so immersed in the ASP.NET AJAX world any more, so I can’t offer any additional suggestions.

    Sorry!

    Damian


Leave a comment

No trackbacks yet.