Checking to see if username exists
<p>I am beginning work on coding a site and at the moment I am doing a user creation page.  All the validation works fine, but I am unsure what to put into the checkUsername method in order to verify that the username does not already exist.  Below is my ASP.NET code.</p>

<pre><code>&lt;asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"&gt;
  &lt;p&gt;
  &lt;asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="There were errors on the page:" /&gt;
  &lt;/p&gt;
  &lt;p&gt;
      &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"  ControlToValidate="username" ErrorMessage="Username is required."&gt; *&lt;/asp:RequiredFieldValidator&gt;
  Enter Username &lt;asp:TextBox ID="username" runat="server"&gt;&lt;/asp:TextBox&gt;
     &lt;asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="username" ErrorMessage="Username must be 4-10 letters or numbers." ValidationExpression="[a-zA-Z0-9]{4,10}" /&gt;
        &lt;asp:CustomValidator ID="CustomValidator1" runat="server" controltovalidate="username" errormessage="Username is already in use." OnServerValidate="checkUsername" /&gt;
 &lt;/p&gt;
 &lt;p&gt;
 Enter Password &lt;asp:TextBox ID="entPWD" runat="server" TextMode="Password"&gt;&lt;/asp:TextBox&gt;
        &lt;asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" display="dynamic" ControlToValidate="entPWD" ErrorMessage="Password must contain one of the following: @#$%^&amp;*/." ValidationExpression=".*[@#$%^&amp;*/].*" /&gt;
        &lt;asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" display="dynamic" ControlToValidate="entPWD" ErrorMessage="Password must be 6-12 characters." ValidationExpression="[^\s]{6,12}" /&gt;
 &lt;/p&gt;
 &lt;p&gt;
 Confirm Password &lt;asp:TextBox ID="confPWD" runat="server" TextMode="Password"&gt;&lt;/asp:TextBox&gt;
        &lt;asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="entPWD" ControlToCompare="confPWD" ErrorMessage="Passwords do not match." /&gt;
    &lt;/p&gt;
    &lt;asp:Button type="submit" ID="Button1" runat="server" Text="Submit" /&gt;
&lt;/asp:Content&gt;
</code></pre>

<p>And this is my Code Behind:</p>

<pre><code>public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    private bool checkUsername(string username)
    {
        string connString = "Data Source=serveraddress;Initial Catalog=database;User Id=username;Password=password;";
        string cmdText = "SELECT COUNT(*) FROM igs_users WHERE username = @username";

        using(SqlConnection conn = new SqlConnection(connString))
            {
            conn.Open();

            using(SqlCommand cmd = new SqlCommand(cmdText, conn))
                {
                cmd.Parameters.AddWithValue("@username", username);

                int count = (int)cmd.ExecuteScalar();

                return (count &gt; 0);
                }
            }
    }
}
</code></pre>

<p>When I run the code, I get the following error message:</p>

<pre><code>Compiler Error Message: CS1061: 'ASP.default_aspx' does not contain a definition for 'checkUsername' and no extension method 'checkUsername' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?)
</code></pre>

<p>Not sure where I am going wrong.  I have using System.Data.SqlClient; in the Code Behind and also added a reference to system.data.dll.</p>

<p>Any help would be appreciated!</p>
