ASP.NET Ajax exception - Two components with the same id can't be added to the application
There's a couple of exceptions to look out for when you start developing custom ASP.NET Ajax client controls. They are:
Microsoft JScript runtime error: Sys.InvalidOperationException: Two components with the same id 'ctl00_MainContentPlaceHolder__eventsRepeater_ctl01_ke1' can't be added to the application.
and...
Microsoft JScript runtime error: Sys.InvalidOperationException: A control is already associated with the element.
These errors can be caused when you have a custom control/component which gets added and then re-added at some later point in time - such as when you have a partial page render. This is being caused because the Sys.Control or Sys.Component gets registered with the Sys.Application when you call the initialize method of your component like so:
MarkItUp.Web.MyCustomControl.callBaseMethod(this, 'initialize') ;
Under the hood, the Sys.Application keeps a list of all the components that are registered with it - that's how $find works. So when you call 'initialize', Sys.Application looks at the list of components that it currently knows about and if yours already exists then you will likely see one of the errors listed above.
The trick is to make sure that you call dispose on your control's base when you are finished:
dispose : function() {
$clearHandlers(this.get_element()) ;
// any other cleanup workMarkItUp.Web.MyCustomControl.callBaseMethod(this, 'dispose') ;
}
FROM:
http://showusyourcode.spaces.live.com/Blog/cns!15630F96CB7D86C1!582.entry
http://forums.asp.net/p/1066748/1548516.aspx
http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/Q_23735231.html
http://www.eggheadcafe.com/software/aspnet/30226324/two-components-with-the-s.aspx
http://bytes.com/groups/net-asp/669319-two-components-same-id-cant-added-application
http://www.codeplex.com/AjaxControlToolkit/WorkItem/View.aspx?WorkItemId=8904
http://www.nikhilk.net/Entry.aspx?id=152
http://forums.asp.net/p/1342154/2719761.aspx#2719761
http://66.129.67.4/t/1094818.aspx
http://www.codeplex.com/AjaxControlToolkit/WorkItem/View.aspx?WorkItemId=10945
Calendar Extender generates message "Sys.InvalidOperationException: Two components with the same id '{ExtenderId}' can't be added to the application error." when the container update panel is refreshed
http://forums.asp.net/t/1127745.aspx
Sys.InvalidOperationException: Two components with the same id 'bsdate' can't be added to the application
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY