Two components with the same id AJAX error

While debugging a script control written with ASP.NET AJAX, we came across this weird exception:

Sys.InvalidOperationException: Two components with the same id '[....]' can't be added to the application.

The control looked kosher in every respect. Yet we couldn’t understand why the client-side “runtime” was trying to create another instance of this script control on every AJAX call. It’s as if it wouldn’t let go of an old instance before attempting to create a new one.

Looking for a solution in Google, it became obvious there were many various causes of the above exception, but one stood out: make sure you call the base dispose in your script control.

I looked at my dispose method:

dispose : function () {   
	delete this._remove$delegate;   
	delete this._add$delegate; 
	}

Duh! It should’ve looked as follows:

dispose : function () {   
 delete this._remove$delegate;    
delete this._add$delegate;    
[my namespace].[my class].callBaseMethod (this, "dispose"); 
}

A self-inflicted painful lesson. I hope it saves somebody debugging time.

posted @ 2011-04-13 16:23  蓝色没耳朵猫  阅读(238)  评论(0编辑  收藏  举报