0

I am using the best tutorial of encosia website which was written by David ward and by his example given in his website for instant validation of username.

Here is the link of the original post: http://encosia.com/aspnet-username-availability-checking-via-ajax/

So the problem here with this code is though I am using my custom membership it is always showing me the user is "Available" instead of "Not Available" if the user is not in the database.

Here is my code:

      protected void Username_Changed(object sender, EventArgs e)
  {
    System.Threading.Thread.Sleep(2000);

    if (Membership.GetUser(Username.Text) != null)
    {
      UserAvailability.InnerText = "Username taken, sorry.";
      UserAvailability.Attributes.Add("class", "taken");
      Button1.Enabled = false;
    }
    else
    {
      UserAvailability.InnerText = "Username available!";
      UserAvailability.Attributes.Add("class", "available");
      Button1.Enabled = true;
    }
  }

This is my web.config:

     <connectionStrings>
    <remove name="LocalSqlServer"/>
    <add name="LocalSqlServer"
     connectionString="Data Source=.\sqlexpress;Initial Catalog=CustomMembership;Integrated Security=True"
       providerName="System.Data.SqlClient"/>
  </connectionStrings>

 <membership defaultProvider="CustomMembership">
      <providers>
        <add name="CustomMembership"
            connectionStringName="LocalSqlServer"
            enablePasswordReset="true"
            enablePasswordRetrieval="false"
            passwordFormat="Hashed"
            maxInvalidPasswordAttempts="5"
            minRequiredPasswordLength="7"
            minRequiredNonalphanumericCharacters="0"
            requiresQuestionAndAnswer="false"
            requiresUniqueEmail="true"
            passwordAttemptWindow="5"
            passwordStrengthRegularExpression=""
            type="System.Web.Security.SqlMembershipProvider" />
      </providers>
    </membership>
5
  • Unrelated, but why you do System.Threading.Thread.Sleep(2000);? Commented Sep 22, 2011 at 16:49
  • When the user enters the name and hits the tab button then just I need o update the progress so I used it. Commented Sep 22, 2011 at 16:50
  • Did you create user database using aspnet_regsql? Commented Sep 22, 2011 at 16:51
  • Try debugging Username.Text, or set someLabel.Text = Username.Text to check if it is properly passed to method. Commented Sep 22, 2011 at 16:53
  • Yes I did the debugging actually it's jumpinng over to jquery 1.3 file so I couldn't trace out the username. Commented Sep 22, 2011 at 16:55

1 Answer 1

1

try replacing (Username.Text) with (sender as TextBox).Text, if protected void Username_Changed is triggered by change in textbox

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.