title: check if username is available or taken
body: <p>I have a simple application in ASP.NET C# and using MS SQL Server 2008. I need to register all visitor users to my site. For that users will have to fill a form.
  The problem is that as the user enters the <strong>Desired Username</strong> field, I should be able to check in background whether another user has already taken that <strong>username</strong>. I will have to fire an sql select query to check for the availability. </p>
  
  <p>Currently I am using the <code>TextBoxName_TextChanged</code> method but it does not work in realtime. It works only on a postback. The code is that follows:</p>
  
  <pre><code>protected void TextBox3_TextChanged(object sender, EventArgs e)
          {
              if (TextBox3.Text.Length == 0)
              {
                  availability.Text = "";
                  return;
              }
  
              SqlDataAdapter adp = new SqlDataAdapter("select username from users where username='" + TextBox3.Text + "'", con);
              DataSet ds = new DataSet();
              adp.Fill(ds, "users");
              if (ds.Tables["users"].Rows.Count &gt; 0)
              {
                  availability.ForeColor = System.Drawing.Color.Red;
                  availability.Text = "Not Available";
              }
              else
              {
                  availability.ForeColor = System.Drawing.Color.White;
                  availability.Text = "Available";
              }
  
          }
  </code></pre>
  
  <p>Please  suggest me something as all I searched on web was about PHP, Not ASP.NET</p>
  
  <pre><code>&lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt;
  &lt;/asp:ScriptManager&gt;
  &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
  &lt;/asp:UpdatePanel&gt;
      &lt;table cellpadding="5" class="style1"&gt; 
          &lt;tr&gt;
              &lt;td class="style3"&gt;
                  &lt;asp:Label ID="Label3" runat="server" Text="Username" ForeColor="White"&gt;&lt;/asp:Label&gt;&amp;nbsp;&amp;nbsp; &lt;/td&gt;
              &lt;td style="border:0px none #FF0000;"&gt;
                  &lt;asp:TextBox ID="TextBox3" runat="server" Width="175px" 
                      CssClass="input-control" ForeColor="Black" ontextchanged="TextBox3_TextChanged" AutoPostBack="true"&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class="style3"&gt;&lt;/td&gt;
              &lt;td style="border:0px none #FF0000;"&gt; 
  
                  &lt;asp:Label ID="availability" runat="server" Width="175px" CssClass="text" Text="availability"&gt;&lt;/asp:Label&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class="style3"&gt;
                  &lt;asp:Label ID="Label4" runat="server" Text="Password" ForeColor="White"&gt;&lt;/asp:Label&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/td&gt;
              &lt;td style="border:0px none #FF0000;"&gt;
                  &lt;asp:TextBox ID="TextBox4" runat="server" Width="175px" TextMode="Password" CssClass="input-control" ForeColor="Black"&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class="style3"&gt;
                  &lt;asp:Label ID="Label5" runat="server" Text="Email" ForeColor="White"&gt;&lt;/asp:Label&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/td&gt;
              &lt;td style="border:0px none #FF0000;"&gt;
                  &lt;asp:TextBox ID="TextBox5" runat="server" Width="175px" CssClass="input-control" ForeColor="Black"&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
  
              &lt;td class="style3"&gt;
  
              &lt;td style="width:30%; text-align: right; padding: 10px; border:none;"&gt;
                  &lt;div class="button-set" data-role="button-set"&gt;
                      &lt;asp:Button ID="Button2" runat="server" class="active bg-color-red" Text="Sign Up" /&gt;
                  &lt;/div&gt;
          &lt;/tr&gt;
          &lt;/table&gt;&lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <hr>
  
  <p>Update:</p>
  
  <p>Following Everybody's comments and answers I have achieved this much with a little problem shown in this screenshot: <img src="https://i.stack.imgur.com/oH84P.png" alt="Screenshot">
  Don't know why there are another label with status and the <strong>availability_status</strong> stays as it is. Please help.</p>