title: ASP.NET DataSource Control "does not have a naming container" exception
body: <p>I've been getting this exception in my code and wondered if anyone could help me out.</p>
  
  <p>I have a Repeater Control bound to an ObjectDataSource, and the itemtemplate for the repeater contains a User Control (ASCX).  This user control in turn contains several other controls, mainly a GridView that is associated with an ObjectDataSource.</p>
  
  <p>On initial use of the controls in this setup, everything works great - data displays properly.  However, when I change a filter option (dropdowns outside of the repeater), and then rebind the Repeater, I get the exception:</p>
  
  <p>The ObjectDataSource control 'expDataSource' does not have a naming container.  Ensure that the control is added to the page before calling DataBind."
  at System.Web.UI.WebControls.DataBoundControlHelper.FindControl(Control control, String controlID)
  ...
  ...
  at System.Web.UI.WebControls.ObjectDataSource.LoadCompleteEventHandler(Object sender, EventArgs e)</p>
  
  <p>I'm not sure what the problem is - I've read in a few places that moving the datasource outside of the ASCX control might help - this does nothing.  The objectdatasource appears to be properly structured, and as I said, it works the first time (only).</p>
  
  <p>I noticed in the stack trace for the exception that this is occurring when ASP.NET is calling FindControl() after LoadComplete() occurs.  If I step through my code, it appears as though all my code is finished executing before this happens, so it's all "system" code.</p>
  
  <p>Why would ASP.NET not be able to find this datasource control in the LoadComplete Handler?</p>
  
  <p>Thanks!</p>
  
  <p>Other Notes:</p>
  
  <ul>
  <li><p>This error occurs every other time.  So the first time the data loads properly, then on second refresh fails with this error.  Clicking "Load" again, it works (on the third time).</p></li>
  <li><p>On the times that it fails, it looks like "Page_Load" is being called twice in the ASCX control.  So the patterns are:</p>
  
  <ol>
  <li>Working Pattern:</li>
  </ol></li>
  <li>Page_Load on Parent Page</li>
  <li>Page_Load on ASCX</li>
  <li><p>Data Loads fine</p>
  
  <ol start="2">
  <li>Failing Pattern:</li>
  </ol></li>
  <li>Page_Load on Parent Page</li>
  <li>Page_Load on ASCX</li>
  <li>Page_Load on ASCX</li>
  <li>Exception</li>
  </ul>
  
  <p>This is all happening from a call to "Repeater.DataBind()", but it behaves differently depending on if it has already been bound or not (evidently).</p>
  
  <p>More Notes:</p>
  
  <p>Real strange behavior.  I removed the list of SelectParameters from the bottom of the ObjectDataSource, and all of a sudden, the page does not reject the ObjectDataSource as not having a NamingContainer.  Of course, without these parameters, Databinding won't actually work...I can add them in the code, but why would it matter?</p>