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>