I'm assigning an onclick handler to a checkbox. Sometimes javascript that does the binding of event runs more than once (on partial postbacks) and the handler gets assigned twice. How can I prevent the handler from being assigned multiple times?
Okay thanks for responses. I wrote something up to figure out if element has a hanlder:
$.fn.hasHandler = function(eventName, handler)
{
var _hasHandler = false;
if(handler != undefined && this.data("events") !== null && this.data("events") !== undefined)
{
$.each(this.data("events"), function(name, handlers)
{
if(name === eventName)
{
$.each(handlers, function(index, value)
{
if(value.handler === handler)
{
_hasHandler = true;
}
});
}
});
}
return _hasHandler;
}