title: Usercontrol losing Viewstate across Postback
body: <p>I have a user control which uses objects as inner properties (some code is below). </p>
  
  <p>I am having trouble with setting the attribute of the Step class programmatically, when set programmatically it is being lost across postback which would indicate something to do with Viewstate (?). </p>
  
  <p>When setting the property of the Step class declaratively it's working fine.  </p>
  
  <p>Does anybody have any ideas of what this code be/what's causing it to lose the state across postback?</p>
  
  <p><strong>ASPX Page</strong></p>
  
  <pre><code>    &lt;uc1:StepControl ID="StepControl1" runat="server"&gt;
          &lt;Step1 Title="1. Select your Products" Enabled="true"&gt;
              &lt;Content&gt;
  
                  &lt;div class="clearfix"&gt;
                      &lt;div class="floatRight"&gt;
                          &lt;asp:Button ID="btnGoToStep2" 
                          runat="server" 
                          Text="Next" 
                          CausesValidation="false" 
                          OnClick="btnGoToStep2_OnClick" /&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
  
              &lt;/Content&gt;
          &lt;/Step1&gt;
          &lt;Step2 Title="2. Select your Features"&gt;      
              &lt;Content&gt;
  
                  &lt;div class="clearfix"&gt;
                      &lt;div class="floatLeft"&gt;
                          &lt;asp:Button ID="btnBackToStep1" 
                          runat="server" 
                          Text="Back" 
                          CausesValidation="false" 
                          OnClick="btnBackToStep1_OnClick" /&gt;
                      &lt;/div&gt;                    
                      &lt;div class="floatRight"&gt;
                          &lt;asp:Button ID="btnGoToStep3" 
                          runat="server" 
                          Text="Next" 
                          CausesValidation="false" 
                          OnClick="btnGoToStep3_OnClick" /&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;                    
  
              &lt;/Content&gt;
          &lt;/Step2&gt;                     
      &lt;/uc1:StepControl&gt;
  </code></pre>
  
  <p><strong>ASPX code behind</strong></p>
  
  <pre><code>    protected void btnGoToStep2_OnClick(object sender, EventArgs e)
      {
          StepControl1.Step1.StatusText = "4 Products Selected";
      }
  
      protected void btnBackToStep1_OnClick(object sender, EventArgs e)
      {
          // StatusText (of Step1) gets lost at this point. 
      }
  </code></pre>
  
  <p><strong>User control code behind</strong></p>
  
  <pre><code>public partial class StepControl : System.Web.UI.UserControl
  {
      [PersistenceMode(PersistenceMode.InnerProperty)]
      [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
      [NotifyParentProperty(true)]
      public Step Step1 { get; set; }
  
      [PersistenceMode(PersistenceMode.InnerProperty)]
      [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
      [NotifyParentProperty(true)]
      public Step Step2 { get; set; }
  
      protected void Page_Init(object sender, EventArgs e)
      {
          AddSteps();
      }
  
      private void AddSteps() { }
  }
  
  [Serializable()]
  [ParseChildren(true)]
  [PersistChildren(false)]
  public class Step
  {
      [PersistenceMode(PersistenceMode.Attribute)]
      public string Title { get; set; }
  
      [PersistenceMode(PersistenceMode.Attribute)]
      public string Status { get; set; }
  
      [PersistenceMode(PersistenceMode.InnerProperty)]
      [TemplateInstance(TemplateInstance.Single)]
      [TemplateContainer(typeof(StepContentContainer))]
      public ITemplate Content { get; set; }
  
      public class StepContentContainer : Control, INamingContainer { }
  }
  </code></pre>