use this in text changed event
// to check the emailid available or not
protected void unametxt_txtchanged(object sender, EventArgs e)
{
if (uname_txt.Text != string.Empty)
{
string strConnection = "Database=dbname;Data Source=sqlexpress;Integrated Security=true";
string strSelect = "SELECT * FROM user_register WHERE user_name = @user_name1";
SqlConnection con = new SqlConnection(strConnection);
SqlCommand cmd = new SqlCommand(strSelect, con);
cmd.Parameters.AddWithValue("user_name1", uname_txt.Text.Trim().ToString());
con.Open();
int result = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
if (result >= 1)
{
imgid2.Visible = true;
imgid.Visible = false;
lblid.Visible = true;
lblid.Text = "Email id already exists";
lblid.ForeColor = System.Drawing.Color.Red;
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('User Cant Registered \n UserName already Exists '); window.location.href = 'Home.aspx';", true);
register_btn.Enabled = false;
}
else
{
register_btn.Enabled = true;
imgid.Visible = true;
imgid2.Visible = false;
lblid.Text = "";
lblid.ForeColor = System.Drawing.Color.Green;
}
}
}
Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator