This is what I did.
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con.Open();
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 == 0)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('User Name Does Not Exist!!! You Must Fill Out Registration First!!!');", true);
TextBoxEA.Text = string.Empty;
}
else if (temp == 1)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Invalid UserName/Password!!!');", true);
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con.Open();
if (true)
{
SqlCommand level = new SqlCommand("select accessLevel, Password, INST_ID from Tablepass where EmailAddress = @EmailAddress AND Password = @Password", con);
level.Parameters.Add(new SqlParameter("EmailAddress", TextBoxEA.Text));
level.Parameters.Add(new SqlParameter("Password", TextBoxPW.Text));
SqlDataReader reader = level.ExecuteReader();
DataTable dt1 = new DataTable();
dt1.Load(reader);
foreach (DataRow dr1 in dt1.Rows)
{
int returnedLevel = Convert.ToInt32(dr1[0].ToString());
int inst_id = Convert.ToInt32(dr1[2].ToString());
Session["inst_id"] = inst_id;
if (returnedLevel == 1)
{
Response.Redirect("FormAPublic.aspx");
}
else if (returnedLevel == 2)
{
Response.Redirect("FormCPrivateNon.aspx");
}
else if (returnedLevel == 3)
{
Response.Redirect("FormDPrivateFor.aspx");
}
else if (returnedLevel == 7)
{
Response.Redirect("CEOPage.aspx");
}
else if (returnedLevel == 8)
{
Response.Redirect("DBPage.aspx");
}
else if (returnedLevel == 11)
{
Response.Redirect("FormAPublicL.aspx");
}
else if (returnedLevel == 21)
{
Response.Redirect("FormCPrivateNonL.aspx");
}
else if (returnedLevel == 31)
{
Response.Redirect("FormDPrivateForL.aspx");
}
else if (returnedLevel == 0)
{
Response.Redirect("Oops2.aspx");
}
}
}
}
}
I took out the
TextBoxEA.Text = string.Empty;
from the error message and I was able to Login. The error still displays when you enter an invalid username and password. Thanks.