title: get value from textbox within repeater asp.net c#
body: <p>I've been trying to get this working for a couple of hours now but nothing from google could help me fix the problem.</p>
  
  <p>I have a very simple repeater control:</p>
  
  <pre><code>   &lt;asp:Panel ID="userDefDiv" Visible="false" runat="server"&gt;
                  &lt;asp:Repeater ID="userDefRepeater" EnableViewstate="false" runat="server"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:TextBox ID="TextBox1" runat="server" EnableViewState="false"&gt;&lt;/asp:TextBox&gt;&lt;br/&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:Repeater&gt;
              &lt;/asp:Panel&gt;
  </code></pre>
  
  <p>the userDefDiv panel is inside another panel, which is inside contentPLaceHolder.
  the parent panel to userDefDiv does NOT have the "enableviewstate="false"".</p>
  
  <p>So.
  Everything on this page happens after a couple of linkbuttons_click. so nothing happens during page_load. And after i click another linkbutton i want to get the data from the different textboxes that is within the repeater.</p>
  
  <p>C# code:</p>
  
  <p>This is the code to create all the repeater items.</p>
  
  <pre><code>public void createUserDef()
  {
          DataTable userDefData;
          userDefData = ..... (data from Database.)
  
              userDefDiv.Visible = true;
              userDefRepeater.DataSource = userDefData;
              userDefRepeater.DataBind();
  }
  </code></pre>
  
  <p>The code for the linkbutton:</p>
  
  <pre><code>protected void linkButton_Click(object sender, EventArgs e)
  {
      createUserDef();
  
      Label2.Visible = true;
      foreach (RepeaterItem item in userDefRepeater.Items)
      {
          TextBox box = (TextBox)item.FindControl("TextBox1");
          string b = box.Text;
          Label2.Text += b + " . ";
      }
  }
  </code></pre>
  
  <p>As you see i create the repeater once again during the click. But the only thing i can read in label2. is a a number of " .", on dot for each textbox.
  but the text from the textbox is empty..
  What am I doing wrong??</p>
  
  <p>thanks for reading!
  Mattias</p>
  
  <p>SOLUTION:</p>
  
  <ol>
  <li><p>add EnableVIewState="true" to textbox &amp; repeater. </p></li>
  <li><p>Dont call call dataBind() before you get the values.</p></li>
  </ol>
  
  <p>Thanks!</p>