title: Bug in Label ASP.ViewState implementation?
body: <p>EDIT 2: Well, I went to the code. Note what they are doing here. They are saying load viewstate, and then turning around and setting the Text property to what was in the viewstate. After LoadViewState is called though viewstate tracking is on, and that results in the behavior I'm seeing. I think what the code should say is:</p>
  
  <p>if (s != Text) {Text = s;}. That would get rid of the issue altogether and keep whatever invariant they need in place. </p>
  
  <pre><code>/// &lt;internalonly/&gt;
          /// &lt;devdoc&gt;
          ///    &lt;para&gt;Load previously saved state.
          ///       Overridden to synchronize Text property with LiteralContent.&lt;/para&gt; 
          /// &lt;/devdoc&gt;
          protected override void LoadViewState(object savedState) { 
              if (savedState != null) { 
                  base.LoadViewState(savedState);
                  string s = (string)ViewState["Text"]; 
                  if (s != null)
                      Text = s;
              }
          } 
  </code></pre>
  
  <p>Edit: From all my tests this appears to only affect the Label control. I still think this is a bug. </p>
  
  <p>This is an ASP.NET 3.5 Website.</p>
  
  <p>Consider the following .aspx page:
  (html, head, body, etc. snipped)</p>
  
  <pre><code>&lt;form id="form1" runat="server"&gt;
          &lt;asp:Label runat="server" ID="label1"&gt;
              This is a lot of text. 
              This is a lot of text. 
              This is a lot of text. 
              This is a lot of text. 
              This is a lot of text. 
              This is a lot of text. 
              This is a lot of text.             
          &lt;/asp:Label&gt;
          &lt;asp:Button runat="server" ID="button1" Text="Click" OnClick="button1_Click" /&gt;
          &lt;script&gt;
              document.write(document.getElementById("__VIEWSTATE").value.length);
          &lt;/script&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>The page has the following code behind:</p>
  
  <pre><code>protected void button1_Click(object sender, EventArgs e) {
          //label1.AccessKey = "a";
      }
  </code></pre>
  
  <p>Yes, that line is commented out. Coming to that. So, when you click the button you will see that viewstate is 52 bytes. Even though the label has lots of text, of course the way viewstate works is that it doesn't need to save the lots of text in the viewstate because the initial value of the Text property never changed. OK. So far so good. This is all expected behavior. In fact, even if the label contained 1 meg of text, the viewstate size would still be 52 bytes. OK. Now change the method to </p>
  
  <pre><code>protected void button1_Click(object sender, EventArgs e) {
          label1.AccessKey = "a";
      }
  </code></pre>
  
  <p>It doesn't matter what property we change. Now click the button. ViewState size goes up to 92 bytes. Alright 40 bytes to store a one character access key, a little much if you ask me but whatever :) Now, click the button again. What's the viewstate size now? Should be 92 bytes right? No. It's <em>480</em>. Clicking anymore and it stays at the 480 bytes size. What's happening? Changing the label property caused the label to start storing the label TEXT in the viewstate. What???? Stick a 100K of text in the label and you'll see the viewstate go up to ~100K. </p>
  
  <p>Is this a bug? How is this <em>possibly</em> expected behavior?</p>