protected void txtUsername_TextChanged(object sender, EventArgs e) { if (txtUsername.Text != string.Empty) { string strSelect = "SELECT COUNT(*) FROM tblRegisteredUsers WHERE Username = @Username"; SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(strSelect, con); SqlParameter username = new SqlParameter("@Username", SqlDbType.VarChar); username.Value = txtUsername.Text.Trim().ToString(); cmd.Parameters.Add(username); con.Open(); int result = (Int32)cmd.ExecuteScalar(); con.Close(); if (result >= 1) { imgUsr.ImageUrl = "Images/unavailable.png"; imgUsr.Visible = true; lblUsr.Text = "Username not available"; lblUsr.ForeColor = System.Drawing.Color.Red; } else { imgUsr.ImageUrl = "Images/tick.png"; imgUsr.Visible = true; lblUsr.Text = "Available"; lblUsr.ForeColor = System.Drawing.Color.Green; txtCommonEmail.Focus(); } } }
Use Page.Validate(); if(Page.IsValid) { write ur code here }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)