title: Minimizing ViewState size in ASP.Net, is there a difference between initializing control values in the constructor versus OnInit?
body: <p>Ok I'm trying to understand how best to handle <code>ViewState</code>, for the programmatic setting of default values using C#. I understand that the construction of the <code>ViewState</code> hidden field is based on every value that is set after the <code>OnInit</code> event is triggered. What I'm not clear about is if there is a difference between using the control's constructor or the <code>OnInit</code> event to set default values. </p>
  
  <pre><code>public MyControl(){
      this.Text = "SomeDefaultValue";
  }
  </code></pre>
  
  <p>versus</p>
  
  <pre><code>protected override void OnInit(EventArgs e){
      this.Text = "SomeDefaultValue";
  }
  </code></pre>
  
  <p>I've seen some places that suggest testing the ViewState value for <code>null</code> in the <code>get</code> of the given property, like so:</p>
  
  <pre><code>public string Text {
      get {
          return this.ViewState["Text"] == null ?
              "SomeDefaultValue" :
              this.ViewState["Text"] as string;
      }
      set { this.ViewState["Text"] = value; }
  }
  </code></pre>
  
  <p>I don't like that because it makes clearing the value confusing.</p>
  
  <p>So, Is there any functional difference between using the constructor vs <code>OnInit</code> to set default <code>ViewState</code> values?</p>