title: Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate
body: <p>I'm currently working on a dynamic core for several webprojects. It has a core that uses a treeview and a menu. And then for each specific projekt it loads several different wuc into a maincontent. Some business projects use business related wucs while others uses different ones. So the span of wuc's is really big.</p>
  
  <p>Now to my problem, whenever a user press a menuitem or a treeitem it loads a wuc to the maincontent linked to that object. </p>
  
  <p>But I'm having some viewstate errors and i've been looking around for 2 days now and none of the solutions explained are working for my projekt.</p>
  
  <p>All my wuc has to have viewstate enabled.</p>
  
  <p>Cycle is -></p>
  
  <p>Page(Control A) does postback with variable to change control to ControlB in wucPanel(UpdatePanel).
  OnLoad LoadRequested Wuc.</p>
  
  <p>Current code is</p>
  
  <pre><code>protected void Load_Page(object sender, EventArgs e)
  {
  //Code to decide which wuc to load.
   UserControl wucc = (UserControl)Page.LoadControl(sFilePath);        
   ParentControl.ContentTemplateContainer.Controls.Add(wucc);
  }
  </code></pre>
  
  <p>I've tried several fixes like adding diffrent ids to the wuc, but this either disabels the internal functions of control like handlers etc or generates the same viewstate error.</p>
  
  <p>One solution i found was to load ControlA and then just removing it and then load ControlB. But this disabled the scripts for my 3rd party controller (Telerik). </p>
  
  <p>I've also read about having diffrent PlaceHolders for each typof but since i expect havign up to 50 diffrent Controls I don't feel this is gonna help me. </p>
  
  <p>And moving from Page_Load -> Page_Init generated the same error. </p>
  
  <p>Error: </p>
  
  <blockquote>
    <p>Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.</p>
  </blockquote>