title: Enabling view state is not working with controls in web part
body: <p><strong>What I have?</strong></p>
  
  <p>I have a simple web part which has a <code>Table</code>. The table has two controls, a <code>TextBox</code> and a <code>Button</code>. In <code>CreateChildControls()</code> method, I add the controls to table if <code>!Page.IsPostBack</code> is true. And, table has view state enabled.</p>
  
  <p><strong>What I want to do?</strong></p>
  
  <p>I want the controls in the table to be present after the post back.</p>
  
  <p><strong>What problem am I facing?</strong></p>
  
  <p>I except the the controls, <code>TextBox</code> and <code>Button</code> to be present in the table after the post back. But it is not happening.</p>
  
  <p>I feel building the whole table in every post back is little costly and enabling view state will solve this problem.</p>
  
  <p>Can anyone tell if I am missing something?</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I tried setting <code>EnbleViewState</code> property of web part. Still the same result.</p>
  
  <p>Code:</p>
  
  <pre><code>public class TreeWebPart : Microsoft.SharePoint.WebPartPages.WebPart
      {
          private Table table;
          private Button clickMe;
          private TextBox content;
  
          protected override void CreateChildControls()
          {
              base.CreateChildControls();
  
              BuildTable();
          }
  
          private void BuildTable()
          {
              table = new Table();
              clickMe = new Button();
              content = new TextBox();
  
              table.ID = "myTable";
              table.EnableViewState = true;
  
              if (!this.Page.IsPostBack)
              {
                  clickMe.Text = "Click Me!";
                  clickMe.Click += new EventHandler(clickMe_Click);
  
                  content.Text = "Click button to set text";
                  content.Width = Unit.Pixel(200);
  
                  TableCell cell = new TableCell();
                  cell.Controls.Add(content);
  
                  TableRow tr = new TableRow();
                  tr.Cells.Add(cell);
                  table.Rows.Add(tr);
  
                  cell = new TableCell();
                  cell.Controls.Add(clickMe);
  
                  tr = new TableRow();
                  tr.Cells.Add(cell);
                  table.Rows.Add(tr);
  
              }
              this.Controls.Add(table);
          }
  
          protected void clickMe_Click(object sender, EventArgs e)
          {
              content.Text = DateTime.Now.ToLongDateString() + "  " + DateTime.Now.ToLongTimeString();
          }
      }
  </code></pre>