Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8649433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:33:39+00:00 2026-06-12T13:33:39+00:00

I am beginning work on coding a site and at the moment I am

  • 0

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.

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

And this is my Code Behind:

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 > 0);
                }
            }
    }
}

When I run the code, I get the following error message:

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?)

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.

Any help would be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:33:40+00:00Added an answer on June 12, 2026 at 1:33 pm

    Custom validation methods need the following method signature:

    void checkUsername(object source, ServerValidateEventArgs args)
    

    Instead of passing the username in as a string, the ServerValidateEventArgs will have the value.

    And instead of returning true or false for validation, use this:

    args.IsValid = true; 
    

    See this page for more information on using CustomValidators: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.onservervalidate(v=vs.80).aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It all seemed to work fine in the beginning... rails generate migration add_starting_date_to_announcements starting_date:date
I am just beginning to work with Rails. I have a model, User and
I am beginning to work on my first OpenGL iPhone app, but I've hit
We are beginning work on sharepoint 2007 site and I am looking for ways
I am beginning work on an intelligent firewall but before I do that I
I'm beginning work on a web application that will have several distinct user types,
I'm beginning to work on the caching infrastructure for my ASP.NET MVC site. The
I am beginning work on a relatively large web-based application with the potential for
I'm beginning to work on mailing-list software we use internally (EDIT: though we send
I am just beginning design work on a problem that I'm sure has been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.