You can use TexboxChanged Event and make textbox property Autopostback True.
now in Textbox changed Event :
string pass="select username from tablename where username='"+txt_username.Text+"'";
SqlDataAdapter ad = new SqlDataAdapter(pass,connection object);
DataSet ds = new DataSet();
ad.Fill(ds);
if (ds.Tables[0].Rows.Count != 0)
{
txt_username.Focus();
}
else
{
}
Enjoyyyy
Mitesh