title: Retrieving value from Asp.Net TextBox
body: <p>Problem: I have an asp.net Textbox that I am putting text into and on text change it should assign its value to a variable, this does not happens.</p>
  
  <p>Question: What is the best method to retrieve the value from the Textbox?</p>
  
  <p>C# Code:</p>
  
  <pre><code>protected void btnSourceConnect_Click(object sender, EventArgs e)
  {
      if (Util.Connection(SourceString, 0))
      {
          lblTesting.Text = "Working!";
      }
      else
      {
          lblTesting.Text = "It No Work";
      }
  }
  protected void txtSourceServer_TextChanged(object sender, EventArgs e)
  {
          SourceString.DataSource = txtSourceServer.Text;      
  }
  
  protected void txtSourceDatabase_TextChanged(object sender, EventArgs e)
  {
  
          SourceString.InitialCatalog = txtSourceDatabase.Text;
  
  }
  
  protected void txtSourceUN_TextChanged(object sender, EventArgs e)
  {
  
          SourceString.UserID = txtSourceUN.Text;
  
  }
  
  protected void txtSourcePass_TextChanged(object sender, EventArgs e)
  {
  
          SourceString.Password = txtSourcePass.Text;   
  }
  </code></pre>
  
  <p>Asp.Net Code:</p>
  
  <pre><code>&lt;table style="width: 100%;Border:1px solid Black;"&gt;
      &lt;tr&gt;
              &lt;td class="style1"&gt;
                  &amp;nbsp;
                  Source Server:&lt;/td&gt;
              &lt;td class="style1"&gt;
                  &amp;nbsp;&amp;nbsp;
                  &lt;asp:TextBox ID="txtSourceServer" runat="server" 
                      ontextchanged="txtSourceServer_TextChanged" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;
              &lt;/td&gt;
              &lt;td class="style1"&gt;
                  &amp;nbsp; Source Database:
              &lt;/td&gt;
              &lt;td class="style1"&gt;
                  &amp;nbsp;&amp;nbsp;
                  &lt;asp:TextBox ID="txtSourceDatabase" runat="server" 
                      ontextchanged="txtSourceDatabase_TextChanged" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;
              &lt;/td&gt;
  
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class="style1"&gt;
                  &amp;nbsp; User Name:
              &lt;/td&gt;
              &lt;td class="style1"&gt;
                  &amp;nbsp;&amp;nbsp;
                  &lt;asp:TextBox ID="txtSourceUN" runat="server" 
                      ontextchanged="txtSourceUN_TextChanged" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;
              &lt;/td&gt;
              &lt;td class="style1"&gt;
                  &amp;nbsp; Password:
              &lt;/td&gt;
              &lt;td class="style1"&gt;
                  &amp;nbsp;&amp;nbsp;
                  &lt;asp:TextBox ID="txtSourcePass" runat="server" 
                      ontextchanged="txtSourcePass_TextChanged" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class="style1"&gt;
                  &amp;nbsp;
              &lt;/td&gt;
              &lt;td class="style1"&gt;
                  &amp;nbsp;
              &lt;/td&gt;
              &lt;td class="style1"&gt;
                  &amp;nbsp;
              &lt;/td&gt;
              &lt;td class="style1"&gt;
                  &amp;nbsp;
                  &lt;asp:Button ID="btnSourceConnect" runat="server" Text="Test Connection" 
                      onclick="btnSourceConnect_Click" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;/table&gt;
  </code></pre>