Oh. Well your code implies that the redirect if statements will be used only if page is not valid. You should move your page redirect code to another method like
public string GetRedirect()
{
string redirect = "";
SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con2.Open();
SqlCommand level = new SqlCommand("select accessLevel, INST_ID from Table99 where INST_ID = @INST_ID AND accessLevel = @accessLevel", con2);
level.Parameters.Add(new SqlParameter("INST_ID", TextBoxINST_ID.Text));
level.Parameters.Add(new SqlParameter("accessLevel", TextBoxaccessLevel.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 accessLevel = Convert.ToInt32(dr1[1].ToString());
Session["accessLevel"] = accessLevel;
if (returnedLevel == 1)
{
redirect = "FormAPublic.aspx";
}
else if (returnedLevel == 2)
{
redirect = "FormCPrivateNon.aspx";
}
else if (returnedLevel == 3)
{
redirect = "FormDPrivateFor.aspx";
}
else if (returnedLevel == 11)
{
redirect = "FormAPublicL.aspx";
}
else if (returnedLevel == 21)
{
redirect = "FormCPrivateNonL.aspx";
}
else if (returnedLevel == 31)
{
redirect = "FormDPrivateForL.aspx";
}
else if (returnedLevel == 7)
{
redirect = "CEOPage.aspx";
}
}
con2.Close();
return redirect;
}
Then in your javascript code bit:
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "if(confirm('You Have Successfully Submitted the Cohort! Do you have Additional Cohorts Please Click Yes to Enter another Cohorts? If you are finished entering Cohorts, Please click No.') == false){ window.location.href=" + GetRedirect() + ";}else{window.location.href='Gradrate.aspx';}", true);
By the way, your foraech loop doesn't need to be a loop. I'm assuming, you tell otherwise, that dt1.Rows.Count is 1?