I have a web form that has textboxes and validators on it. When the user clicks on the Save button there should be a message to display and then redirects user back to their home page. The message and the redirect doesn't work. What did I do wrong?
Save Button Properties:
<asp:Button ID="ButtonSave" runat="server" onclick="ButtonSave_Click"
style="font-weight: 700" Text="Save" Width="100px"
CausesValidation="False" />
Code Behind:
protected void ButtonSave_Click(object sender, EventArgs e)
{
SqlConnection con7 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con7.Open();
SqlCommand cmd = new SqlCommand("Insert into Table345 (INST_ID, FT_UNDERGR, DATE, FT_GRAD, FTE_UNDERG, FTE_GRAD, NON_CREDIT, TOTAL_FTE, FCFTUHC, FCFTPBHC, FCPTUHC, FCPTPBHC, NCHC, UnderG12, Postb9, Total123b4b, FTEYR, THCAS) values (@INST_ID, @FT_UNDERGR, @DATE, @FT_GRAD, @FTE_UNDERG, @FTE_GRAD, @NON_CREDIT, @TOTAL_FTE, @FCFTUHC, @FCFTPBHC, @FCPTUHC, @FCPTPBHC, @NCHC, @UnderG12, @Postb9, @Total123b4b, @FTEYR, @THCAS);", con7);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID.Text);
cmd.Parameters.AddWithValue("@FT_UNDERGR", TextBoxFTUG.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@FT_GRAD", TextBoxFTG.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@FTE_UNDERG", TextBoxTHUGDR.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@FTE_GRAD", TextBoxTHGDR.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@NON_CREDIT", TextBoxNCCDR.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@TOTAL_FTE", TextBoxTCNC.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@FCFTUHC", TextBoxTNFUG.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@FCFTPBHC", TextBoxTNFG.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@FCPTUHC", TextBoxTNCPUG.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@FCPTPBHC", TextBoxTNCPG.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@NCHC", TextBoxTNNCC.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@FTEYR", lblYEAR1.Text);
cmd.Parameters.AddWithValue("@DATE", TextBoxDATE.Text);
cmd.Parameters.AddWithValue("@UnderG12", TextBoxTHUG.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@Postb9", TextBoxTHG.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@Total123b4b", TextBoxT1234.Text.Replace(",", ""));
cmd.Parameters.AddWithValue("@THCAS", TextBoxTHCAS.Text.Replace(",", ""));
cmd.ExecuteNonQuery();
if (true)
{
SqlConnection con88 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con88.Open();
SqlCommand level = new SqlCommand("select accessLevel, INST_ID from Tablepass where INST_ID = @INST_ID AND accessLevel = @accessLevel", con88);
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)
{
ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Saved the Enrollment Profile. You may come back to finish entering your data later. You will now be redirect to the Menu Page');location.href='FormAPublic.aspx';", true);
}
else if (returnedLevel == 11)
{
ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Saved the Enrollment Profile. You may come back to finish entering your data later. You will now be redirect to the Menu Page');location.href='FormAPublicL.aspx';", true);
}
else if (returnedLevel == 7)
{
ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Saved the Enrollment Profile. You may come back to finish entering your data later. You will now be redirect to the Menu Page');location.href='CEOPage.aspx';", true);
}
else if (returnedLevel == 3)
{
ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Saved the Enrollment Profile. You may come back to finish entering your data later. You will now be redirect to the Menu Page');location.href='FormDPrivateFor.aspx';", true);
}
else if (returnedLevel == 31)
{
ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Saved the Enrollment Profile. You may come back to finish entering your data later. You will now be redirect to the Menu Page');location.href='FormDPrivateForL.aspx';", true);
}
else if (returnedLevel == 2)
{
ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Saved the Enrollment Profile. You may come back to finish entering your data later. You will now be redirect to the Menu Page');location.href='FormCPrivateNon.aspx';", true);
}
else if (returnedLevel == 21)
{
ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Saved the Enrollment Profile. You may come back to finish entering your data later. You will now be redirect to the Menu Page');location.href='FormCPrivateNonL.aspx';", true);
}
con88.Close();
}
}
}
}