title: Viewstate and Tab container
body: <p>I have the following code for a tab container and i am able to create a tab dynamically but as soon as i try to click to add another tab the previous tab disappears, i can't figure out how to keep viewstate, can someone please help me with this.</p>
  
  <h1>test5.aspx</h1>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="test5.aspx.cs" Inherits="test5" %&gt;
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
          &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt;&lt;/asp:ScriptManager&gt;
  &lt;cc1:tabcontainer id="TabContainer1" visible="true" runat="server" Height="150px"&gt; 
      &lt;cc1:TabPanel ID="Tab0" runat="server" HeaderText="Step 1"&gt;
          &lt;ContentTemplate&gt;
              Test
              &lt;asp:Button ID="add" Text="Add" OnClick="add_Click" runat="server" /&gt;
          &lt;/ContentTemplate&gt;
      &lt;/cc1:TabPanel&gt; 
  &lt;/cc1:tabcontainer&gt;  
  
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h1>test5.aspx.cs</h1>
  
  <pre><code>using AjaxControlToolkit;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  public partial class test5 : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
  
      }
  
      protected void add_Click(object sender, EventArgs e)
      {
          int currentTab = TabContainer1.ActiveTabIndex;
          int nextTab = currentTab + 1;
  
          Button btn = new Button();
          btn.ID = "Add" + nextTab.ToString();
          btn.Text = "Add";
          btn.Click += new EventHandler(add_Click);
  
  
          TabPanel t = new TabPanel();
          t.ID = "Tab" + nextTab;
          t.HeaderText = "Tab:" + nextTab;
          t.Controls.Add(btn);
          TabContainer1.Tabs.Add(t);
      }
  }
  </code></pre>