Home > ASP.Net > Check UserName Availability

Check UserName Availability


Try this  code:

protected void Username_Changed(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(”Server=Database; Initial Catalog=achu; Integrated Security=SSPI”);
SqlCommand cmd = new SqlCommand("select * from aspnet_Users",conn);
conn.Open();
SqlDataReader dr;
System.Threading.Thread.Sleep(3000);
dr = cmd.ExecuteReader();
while (dr.Read())
{
if (TextBox1.Text == dr["UserName"].ToString())
Label1.Text="Username already exists";

else
Label1.Text = "Username available ";

}

or try this code :

protected void Username_Changed(object sender, EventArgs e)
{
if(Membership.GetUser(Username.Text) != null)
{
Label1.Text="Username already exists";
}
else
{
Label1.Text = "Username available ";
}

Good Luck

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: