title: ScriptControl inside UpdatePanel
body: <p>I have a <code>ScriptControl</code> (requires <code>ScriptManager</code>) with JavaScript to handle client-side interactions and <code>ICallbackEventHandler</code> 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 <code>GridView</code> with sorting and it still works.  However, I place the <code>GridView</code> in an <code>UpdatePanel</code> and now whenever I sort I get the following error for each instance:</p>
  
  <p><code>Sys.InvalidOperationException: Two components with the same id 'GridView_ctl02_MyControl' can't be added to the application.</code></p>
  
  <p>Can someone point me in the right direction on how to solve this?  I am assuming <code>ScriptManager</code> is not disposing of the old <code>Sys.UI.Control</code> objects before trying to <code>$create()</code> the new ones with the same ID.  I thought the <code>UpdatePanel</code>/<code>ScriptManager</code> combination would automatically take care of disposing objects that would be replaced?</p>
  
  <p><strong>Edit:</strong> This page appears to support what I thought: <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.registerdispose.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.registerdispose.aspx</a></p>
  
  <blockquote>
    <p>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. <strong>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.</strong></p>
  </blockquote>
  
  <p>Just to double check I placed an <code>alert("dispose " + this.element.id)</code> inside my JavaScript <code>dispose()</code> function.  Every single instance alerts <code>dispose GridView_ctl02_MyControl</code>, but afterwards I get the error that two components can't have the same name <code>GridView_ctl02_MyControl</code>.  I'm at a loss...</p>