Check User Name Availability
Check User Name Availability
Try this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| 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 :
1
2
3
4
5
6
7
8
9
10
| 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
Post a Comment