My Technical Notes

Monday, 29 July 2013

Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.AddHandler method

This Javascript error occurs when using Ajax Toolkit. Apparently, it occurs when you have an UpdatePanel which contains the Target and Close Buttons.

I tried quite a few work arounds but eventually I did a simple hack to remove the error, which is to use window.onerror method.

Copy and paste the following code. Note that it is bad practice to use this sort of code as it could potentially hide other errors.


window.onerror = function (msg, url, num) {
    if (msg) {
        var isAddHandlerException = msg.indexOf('Handler was not added through the Sys.UI.DomEvent.addHandler method.') !== -1
                                    || msg.indexOf('b._events is undefined') !== -1;
        return isAddHandlerException; /* if it is an add handler exception then return true because we are not interested in it. */
    }
}

No comments: