title: Get Updated Value of a UserControl TextBox within a ListView
body: <p>I have a page SendResults.aspx that holds a button and a ListView with ItemTemplate set to a user control (3 labels and 2 textboxes) that gets it's data from a matching object.
  On Page_Load I fill the List with data (this works well).
  When the button is clicked I want to take the user input in the user-control's textboxes and do something with it.
  However I always get the initial value and not the updated one.
  Here is the code:
  The user-control "MatchControl.ascx"</p>
  
  <pre><code>    &lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MatchControl.ascx.cs" Inherits="TotoMondeal.Controls.MatchControl" %&gt;
  &lt;div&gt;
      &lt;asp:Image ID="Team1FlagImage" runat="server" /&gt;
  &lt;asp:Label ID="Team1Label" runat="server" Width="150px"&gt;&lt;/asp:Label&gt;
  &lt;asp:TextBox ID="Team1TextBox" runat="server" MaxLength="2" TextMode="Number" Width="50px" AutoPostBack="true" OnTextChanged="Team1TextBox_TextChanged"&gt;&lt;/asp:TextBox&gt;
  &lt;asp:Label ID="Colon" runat="server" Font-Size="XX-Large" Text=":"&gt;&lt;/asp:Label&gt;
  &lt;asp:TextBox ID="Team2TextBox" runat="server" MaxLength="2" TextMode="Number" Width="50px"&gt;&lt;/asp:TextBox&gt;
  &lt;asp:Label ID="Team2Label" runat="server" Width="150px"&gt;&lt;/asp:Label&gt;
      &lt;asp:Image ID="Team2FlagImage" runat="server" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The user-control code-behind:</p>
  
  <pre><code>public partial class MatchControl : System.Web.UI.UserControl
  {
              public Match Match
      {
          get
          {
              object obj = ViewState["Match"];
              return (obj == null) ? new Match() : (Match)obj;
          }
          set
          {
              ViewState["Match"] = value;
          }
      }
  
      public string Team1Score
      {
          get { return Team1TextBox.Text; }
          set { Team1TextBox.Text = value; }
      }
      public string Team2Score
      {
          get { return Team2TextBox.Text; }
          set { Team2TextBox.Text = value; }
      }
  
  
      protected void Page_Load(object sender, EventArgs e)
      {
          Team1Label.Text = Match.Team1Name;
          Team2Label.Text = Match.Team2Name;
  
          Team1TextBox.Text = Match.Team1Score.ToString();
          Team2TextBox.Text = Match.Team2Score.ToString();
  
          Team1TextBox.Enabled = Match.EnableTextBox;
          Team2TextBox.Enabled = Match.EnableTextBox;
  
          Team1FlagImage.ImageUrl = @"~/FlagImages/" +Match.Team1Name + ".png";
          Team2FlagImage.ImageUrl = @"~/FlagImages/" + Match.Team2Name + ".png";
  
      }
  
  
      protected void Team1TextBox_TextChanged(object sender, EventArgs e)
      {
          TextBox textBox = sender as TextBox;
  
          if (textBox != null)
          {
              try
              {
                  Match updatedMatch = new Match()
                  {
                      MatchId = Match.MatchId,
                      MatchDate = Match.MatchDate,
                      Result = Match.Result,
                      Team1Name = Match.Team1Name,
                      Team1Score = Convert.ToInt32(textBox.Text),
                      Team2Name = Match.Team2Name,
                      Team2Score = Match.Team2Score,
                      EnableTextBox = Match.EnableTextBox
                  };
  
                  Match = updatedMatch;
              }
              catch (Exception ex)
              {
                  throw ex;
              }
          }
      }
  </code></pre>
  
  <p>The SendResults.aspx:</p>
  
  <pre><code>&lt;%@ Page Title="שלח תוצאות" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="SendResults.aspx.cs" Inherits="TotoMondeal.SendResults" %&gt;
  &lt;%@ Register TagPrefix="TOTO" TagName="MatchControl" Src="~/Controls/MatchControl.ascx" %&gt;
  &lt;asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"&gt;
      &lt;h2&gt;&lt;%: Title %&gt;.&lt;/h2&gt;
      &lt;div class="jumbotron"&gt;
          &lt;asp:ListView ID="TodayMatchesList" runat="server"&gt;
              &lt;ItemTemplate&gt;
                  &lt;TOTO:MatchControl ID="MatchControl" Match="&lt;%# Container.DataItem %&gt;" runat="server" /&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:ListView&gt;
  
          &lt;asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /&gt;
  
      &lt;/div&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>the SendResults code-behind:</p>
  
  <pre><code>public partial class SendResults : Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
              List&lt;Match&gt; matches = new List&lt;Match&gt;();
              matches = Queries.GetTodayMatches(DateTime.Now);
              foreach (Match match in matches)
              {
                  match.EnableTextBox = true;
              }
              this.TodayMatchesList.DataSource = matches;
              this.TodayMatchesList.DataBind();
      }
  
      protected void Button1_Click(object sender, EventArgs e)
      {
          for (int i = 0; i &lt; TodayMatchesList.Items.Count; i++)
          {
              MatchControl match = (MatchControl)TodayMatchesList.Items[i].FindControl("MatchControl");
              TextBox textBox = (TextBox)match.FindControl("Team1TextBox");
              string txt = textBox.Text;
          }
      }
  }
  </code></pre>
  
  <p>The problem is that in this line:
  TextBox textBox = (TextBox)match.FindControl("Team1TextBox");
  string txt = textBox.Text;</p>
  
  <p>I always get the initial value from the database, and not the user updated input.</p>
  
  <p>Please help I'm new at this.</p>