title: Button click to add string to List<string>
body: <p>I would like to have a button that when clicked will take the text of what's inside the text box and add it to a list of strings.  Then, I have another button that when clicked will output the count of the list into another text box.  I keep on getting a count of zero, no matter what I try.  Can someone help me with what I'm doing wrong?</p>
  
  <p>c#</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  public partial class _Default : System.Web.UI.Page
  {
      List&lt;string&gt; itemList = new List&lt;string&gt;();
      protected void Page_Load(object sender, EventArgs e)
      {
  
      }
      protected void Button1_Click(object sender, EventArgs e)
      {
          itemList.Add(txtItem.Text);
          txtItem.Text = "";
      }
      protected void Button2_Click(object sender, EventArgs e)
      {
          txtItemListCount.Text = itemList.Count.ToString();
  
      }
  }
  </code></pre>
  
  <p>markup</p>
  
  <pre><code>&lt;%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
      CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;
  
  &lt;asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"&gt;
  
  
      &lt;asp:TextBox ID="txtItem" runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;asp:TextBox TextMode="MultiLine" ID="txtItemListCount" runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;asp:Button ID="Button2" runat="server" Text="Button 2" 
          onclick="Button2_Click" /&gt;
  
  
  &lt;/asp:Content&gt;
  </code></pre>