protected void txtUserName_TextChanged(object sender, EventArgs e) { lblException.Text = ""; RegExp Reg = new RegExp(); bool Name = Reg.IsAlpha(txtUserName.Text); if (Name) { con.Close(); con.Open(); SqlCommand cmd = new SqlCommand("select LogName from Login where LogName='" + txtUserName.Text.ToString() + "'", con); string chk = Convert.ToString(cmd.ExecuteScalar()); if (chk == txtUserName.Text.ToString().ToUpper()) { lblActiveId.Text = txtUserName.Text.ToString() + " is Not available."; lblActiveId.ForeColor = System.Drawing.Color.Maroon; txtUserName.Text = ""; txtUserName.Focus(); } else { lblActiveId.Text = txtUserName.Text.ToString() + " is available."; lblActiveId.ForeColor = System.Drawing.Color.Green; txtPassword.Focus(); } con.Close(); con.Dispose(); } else { lblActiveId.Text = txtUserName.Text.ToString() + " is Not available."; lblActiveId.ForeColor = System.Drawing.Color.Maroon; txtUserName.Focus(); txtUserName.Text = ""; } }