You can try that in code behind...Try this code its work..
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(TextBox1.Text))
{
SqlConnection con;
SqlCommand cmd;
string constr = ConfigurationManager.ConnectionStrings["SomeDataBase"].ToString();
con = new SqlConnection(constr);
cmd = new SqlCommand("Select * from Thi where Username=@Username", con);
con.Open();
cmd.Parameters.AddWithValue("@Username", TextBox1.Text);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
checkusername.Visible = true;
imgstatus.ImageUrl = "Images/NotAvailable.jpg";
Label3.Text = "UserName Already Taken";
if (Label3.Text == "UserName Already Taken")
{
TextBox1.Text = " ";
}
System.Threading.Thread.Sleep(2000);
}
else
{
checkusername.Visible = true;
imgstatus.ImageUrl = "Images/Icon_Available.gif";
Label3.Text = "UserName Available";
System.Threading.Thread.Sleep(1000);
con.Close();
}
}
else
{
checkusername.Visible = false;
}
}
Happy coding.