title: Getting values from textbox in the repeater in button click event
body: <p>I have a TextBox in a repeater that is populated from the database in the ItemDataBound event. When I tried to get the text inside the TextBox in a Button_Click event I found the TextBox.Text empty. How can I get the Text?</p>
  
  <pre><code>    foreach (RepeaterItem repeated in repEdit.Items)
      {
          DropDownList drp = (DropDownList)FindControlRecursive(repeated, "drpdown");
          TextBox txt = (TextBox)FindControlRecursive(repeated, "txt");
          CheckBox chk = (CheckBox)FindControlRecursive(repeated, "chk");
          if (drp != null &amp;&amp; !string.IsNullOrEmpty(drp.Attributes["ID"]))
          {
              loc.GetType().GetProperty(drp.Attributes["ID"].Split('#')[0] + "ID").SetValue(loc, int.Parse(drp.SelectedValue), null);
          }
          if (txt != null &amp;&amp; !string.IsNullOrEmpty(txt.Attributes["ID"]))
          {
              if (txt.Attributes["ID"].Contains("#int"))
              {
                  loc.GetType().GetProperty(txt.Attributes["ID"].Split('#')[0]).SetValue(loc, int.Parse(txt.Text), null);    
              }
              else if (txt.Attributes["ID"].Contains("#decimal"))
              {
                  loc.GetType().GetProperty(txt.Attributes["ID"].Split('#')[0]).SetValue(loc, decimal.Parse(txt.Text), null);    
              }
              else
              {
                  loc.GetType().GetProperty(txt.Attributes["ID"].Split('#')[0]).SetValue(loc, txt.Text, null);    
              }
          }
          if (chk!=null &amp;&amp; !string.IsNullOrEmpty(chk.Attributes["ID"]))
          {
              loc.GetType().GetProperty(chk.Attributes["ID"].Split('#')[0]).SetValue(loc, chk.Checked, null);
          }
      }
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>&lt;asp:Repeater ID="repEdit" runat="server" OnItemDataBound="repEdit_ItemDataBound"&gt;
          &lt;ItemTemplate&gt;
              &lt;asp:Label ID="lblName" runat="server" Visible="false"&gt;&lt;/asp:Label&gt;
              &lt;asp:TextBox ID="txt" runat="server" Visible="false"&gt;&lt;/asp:TextBox&gt;
              &lt;asp:CheckBox ID="chk" runat="server" Visible="false" /&gt;
              &lt;asp:DropDownList ID="drpdown" runat="server" Visible="false"&gt;
              &lt;/asp:DropDownList&gt;
              &lt;br /&gt;
          &lt;/ItemTemplate&gt;
  &lt;/asp:Repeater&gt;
  </code></pre>
  
  <p>Here is the itemdatabound event</p>
  
  <pre><code>protected void repEdit_ItemDataBound(object sender, RepeaterItemEventArgs e)
          {
              Label name = e.Item.FindControl("lblName") as Label;
              TextBox text = e.Item.FindControl("txt") as TextBox;
              CheckBox chk = e.Item.FindControl("chk") as CheckBox;
              DropDownList drp = e.Item.FindControl("drpdown") as DropDownList;
              Button but = e.Item.FindControl("butEdit") as Button;
              //butEdit.Visible = true;
              if (but != null)
              {
                  but.Visible = true;
              }
              if (e.Item.ItemType == ListItemType.Item)
              {
                  KeyValuePair&lt;string, Dictionary&lt;int, string&gt;&gt; kvp = (KeyValuePair&lt;string, Dictionary&lt;int, string&gt;&gt;)e.Item.DataItem;
                  if (name != null)
                  {
                      if (kvp.Key.Contains("#datetime"))
                      {
                          return;
                      }
                      name.Visible = true;
                      name.Text = kvp.Key.Split('#')[0].ToString();
                  }
                  if (kvp.Key.Contains("#int") || kvp.Key.Contains("#decimal"))
                  {
                      text.Visible = true;
                      text.ID = kvp.Key;
                      text.EnableViewState = true;
                      text.Attributes["ID"] = kvp.Key;
                      text.Text = kvp.Value[0].ToString();
                      if (kvp.Key.Split('#')[0] == "ID")
                      {
                          text.Enabled = false;
                      }
                  }
  </code></pre>