So, if I enter a username like, Mike, and click on the password TextBox, an error message displays and says, "User Name Already Exist!!!". Then TextBox 1, 2 and 3 are cleared. Then I enter in a username that is in another database the message displays, "User Name Is Available. Please Create Password.". At this time I can create a new password but if I delete the current username and enter a different one that is not in the database I get this message,"User Name Is Available. Please Create Password." with the same data still in TextBox 2 and 3. I then can create a password using the data from the username that was valid and availble. How can I stop this? That is where I am stuck at.
protected void TextBoxEA_TextChanged(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString))
{
con.Open();
SqlCommand scmd = new SqlCommand("Select INST_ID, EmailAddress, accessLevel from Table1 where EmailAddress = @TextBoxEA", con);
SqlCommand scmd2 = new SqlCommand("Select INST_ID, EmailAddress, accessLevel from Table2 where EmailAddress = @TextBoxEA", con);
scmd.Parameters.Add(new SqlParameter("@TextBoxEA", TextBoxEA.Text));
scmd2.Parameters.Add(new SqlParameter("@TextBoxEA", TextBoxEA.Text));
using (SqlDataReader dr = scmd.ExecuteReader())
{
while (dr.Read())
{
TextBoxINST_ID.Text = dr["INST_ID"].ToString();
TextBoxaccessLevel.Text = dr["accessLevel"].ToString();
}
}
using (SqlDataReader dr2 = scmd2.ExecuteReader())
{
while (dr2.Read())
{
TextBoxINST_ID.Text = dr2["INST_ID"].ToString();
TextBoxaccessLevel.Text = dr2["accessLevel"].ToString();
}
}
if (IsPostBack)
{
string cmdStr = "Select count(*) from Tablepass where EmailAddress='" + TextBoxEA.Text + "'";
SqlCommand userExist = new SqlCommand(cmdStr, con);
SqlCommand cmd = new SqlCommand("select INST_ID, EmailAddress from Tablepass", con);
int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
if (temp == 1)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('User Name Already Exist!!!');", true);
TextBoxINST_ID.Text = string.Empty;
TextBoxaccessLevel.Text = string.Empty;
TextBoxEA.Text = string.Empty;
}
else if (temp == 0)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('User Name Is Available. Please Create Password.');", true);
}
}
}
}
}