title: TextBox inside a repeater control
body: <p>I have a repeater control with an <code>ItemTemplate</code> containing two Textboxes. I loop through the Repeater and insert the data in my database. The problem is that the first TextBox is the only one inserted.</p>
  
  <p>I bind the first TextBox in the List in the <code>PageLoad</code> method.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;asp:Repeater ID="questionRepeater" ViewStateMode="Enabled" runat="server"&gt;
      &lt;ItemTemplate&gt;
          &lt;tr class=""&gt;
              &lt;td&gt;
                  &lt;div class="control-group"&gt;
                      &lt;label class="control-label"&gt;Queston  : &lt;/label&gt;
  
                      &lt;div class="controls"&gt;
                          &lt;asp:TextBox runat="server" ID="txtQ" Text='&lt;%#Eval("Question") %&gt;' ReadOnly="true" CssClass="span8"&gt;
                          &lt;/asp:TextBox&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr class="info"&gt;
              &lt;td&gt;
                  &lt;div class="control-group"&gt;
                      &lt;label class="control-label"&gt;Answer : &lt;/label&gt;
                      &lt;div class="controls"&gt;
                          &lt;asp:TextBox runat="server" ID="txtAns"
                              Height="150" TextMode="MultiLine" CssClass="span8"&gt;&lt;/asp:TextBox&gt;
  
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:Repeater&gt;
  </code></pre>
  
  <p>My code behind: </p>
  
  <pre class="lang-csharp prettyprint-override"><code>protected void btnSave_Click(object sender, EventArgs e)
  {
      Sessions session = new Sessions();
      SessionQuestion sessionQuestions = new SessionQuestion();
  
      session.ClientId = id;
      session.DateTime = DateTime.Now;
      session.Report = txtReport.Text;
      session.Notes = string.Empty;
      session.IsActive = IsActive.Active;
  
      int sessionId = SessionBLL.Insert(session);
  
      foreach (Control item in questionRepeater.Items)
      {
          sessionQuestions.SessionId = sessionId;
  
  
          TextBox txtQ = (TextBox)item.FindControl("txtQ");
          sessionQuestions.Answer = "";
          sessionQuestions.Question = txtQ.Text;
  
          var txtAns = (TextBox)item.FindControl("txtAns") as TextBox;
          if (txtAns != null)
          {
              sessionQuestions.Answer = "";
              sessionQuestions.Answer = txtAns.Text; 
          }
  
  
          Thread.Sleep(150);
          if (txtAns != null &amp;&amp; txtQ.Text != null)
          {
              SessionQuestionBLL.Insert(sessionQuestions);
          }
      }
  
      string message = "";
  
      Response.Redirect("/Sessions/Sessions.aspx?message=" + message);
  }
  </code></pre>