I have a ScriptControl
(requires ScriptManager
) with JavaScript to handle client-side interactions and ICallbackEventHandler
to communicate back and forth. Everything works perfectly with one or multiple instances of the control on a page. I placed the control inside a GridView
with sorting and it still works. However, I place the GridView
in an UpdatePanel
and now whenever I sort I get the following error for each instance:
Sys.InvalidOperationException: Two components with the same id 'GridView_ctl02_MyControl' can't be added to the application.
Can someone point me in the right direction on how to solve this? I am assuming ScriptManager
is not disposing of the old Sys.UI.Control
objects before trying to $create()
the new ones with the same ID. I thought the UpdatePanel
/ScriptManager
combination would automatically take care of disposing objects that would be replaced?
Edit: This page appears to support what I thought: http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.registerdispose.aspx
Use the RegisterDispose method to register dispose scripts for controls that are inside an UpdatePanel control. During asynchronous postbacks, UpdatePanel controls can be updated, deleted, or created. When a panel is updated or deleted, any dispose scripts that are registered for controls that are inside the UpdatePanel are called. In typical page development scenarios, you do not have to call the RegisterDispose method.
Just to double check I placed an alert("dispose " + this.element.id)
inside my JavaScript dispose()
function. Every single instance alerts dispose GridView_ctl02_MyControl
, but afterwards I get the error that two components can't have the same name GridView_ctl02_MyControl
. I'm at a loss...