Click here to Skip to main content
15,909,498 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form that when a user logs in it will take them to a welcome page depending on their Level. The user can then click on one of the links to take them to a form where they can fill it out and submit it. When the data is submitted I want it to redirect the user back to the welcome page but it does not. Instead it redirects back to the same page. Why? Is there something I am missing in my code?

Submit Button Code:

C#
protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
        con.Open();

        SqlCommand cmd = new SqlCommand("Insert into Table2013 (INST_ID, TOTAL_REVE, DATE, FINYR, INSTRUCTIO, RESEARCH, ACADEMIC_S, NET_AID, AUXILIARY_, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT) values (@INST_ID, @TOTAL_REVE, @DATE, @FINYR, @INSTRUCTIO, @RESEARCH, @ACADEMIC_S, @NET_AID, @AUXILIARY_, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LONGTERMDEBT)Insert into Table2014 (INST_ID, TOTAL_REVE, DATE, FINYR, INSTRUCTIO, RESEARCH, ACADEMIC_S, NET_AID, AUXILIARY_, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT) values (@INST_ID, @TOTAL_REVE, @DATE, @FINYR, @INSTRUCTIO, @RESEARCH, @ACADEMIC_S, @NET_AID, @AUXILIARY_, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LONGTERMDEBT)", con);

        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID.Text);
        cmd.Parameters.AddWithValue("@TOTAL_REVE", TextBoxTRR.Text);
        cmd.Parameters.AddWithValue("@INSTRUCTIO", TextBoxInstr.Text);
        cmd.Parameters.AddWithValue("@RESEARCH", TextBoxResPs.Text);
        cmd.Parameters.AddWithValue("@ACADEMIC_S", TextBoxAcadSSSIS.Text);
        cmd.Parameters.AddWithValue("@NET_AID", TextBoxNGAS.Text);
        cmd.Parameters.AddWithValue("@AUXILIARY_", TextBoxAuxE.Text);
        cmd.Parameters.AddWithValue("@OTHEREXP", TextBoxAOE.Text);
        cmd.Parameters.AddWithValue("@TOTASSETS", TextBoxTA.Text);
        cmd.Parameters.AddWithValue("@TOTLIABILITY", TextBoxTL.Text);
        cmd.Parameters.AddWithValue("@NoNEXPPERMRESASSETS", TextBoxNPRNA.Text);
        cmd.Parameters.AddWithValue("@EXPENDABLE", TextBoxETRNA.Text);
        cmd.Parameters.AddWithValue("@UNRNETASSETS", TextBoxTUNA.Text);
        cmd.Parameters.AddWithValue("@TOTALREV", TextBoxTR.Text);
        cmd.Parameters.AddWithValue("@TUITFEES", TextBoxTFN.Text);
        cmd.Parameters.AddWithValue("@CURRDEBT", TextBoxCD.Text);
        cmd.Parameters.AddWithValue("@LONGTERMDEBT", TextBoxLTD.Text);
        cmd.Parameters.AddWithValue("@FINYR", lblYEAR.Text);
        cmd.Parameters.AddWithValue("@DATE", TextBoxDATE.Text);

        cmd.ExecuteNonQuery();
        con.Close();

        if (Page.IsValid)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('You Have Successfully Submitted the Financial Profile');", true);
        }

        TextBoxTRR.Text = string.Empty;
        TextBoxInstr.Text = string.Empty;
        TextBoxResPs.Text = string.Empty;
        TextBoxAcadSSSIS.Text = string.Empty;
        TextBoxNGAS.Text = string.Empty;
        TextBoxAuxE.Text = string.Empty;
        TextBoxAOE.Text = string.Empty;
        TextBoxTA.Text = string.Empty;
        TextBoxTL.Text = string.Empty;
        TextBoxNPRNA.Text = string.Empty;
        TextBoxETRNA.Text = string.Empty;
        TextBoxTUNA.Text = string.Empty;
        TextBoxTR.Text = string.Empty;
        TextBoxTFN.Text = string.Empty;
        TextBoxCD.Text = string.Empty;
        TextBoxLTD.Text = string.Empty;
        TextBoxFullN.Text = string.Empty;
        TextBoxTitle.Text = string.Empty;
        TextBoxMA.Text = string.Empty;
        TextBoxTN.Text = string.Empty;
        TextBoxFN.Text = string.Empty;
        TextBoxEA.Text = string.Empty;
        TextBoxTNA.Text = string.Empty;
        TextBoxTNA2.Text = string.Empty;

       
        {
            SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
            con2.Open();

            if (true)
            {
                SqlCommand level = new SqlCommand("select accessLevel, INST_ID from Tablepass where EmailAddress = @EmailAddress", con2);
                level.Parameters.Add(new SqlParameter("EmailAddress", TextBoxEA.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 == 11)
                    {
                        Response.Redirect("FormAPublicL.aspx");
                    }
                    else if (returnedLevel == 21)
                    {
                        Response.Redirect("FormCPrivateNonL.aspx");
                    }
                    else if (returnedLevel == 31)
                    {
                        Response.Redirect("FormDPrivateForL.aspx");
                    }
                }
            }
Posted
Updated 25-Nov-13 4:49am
v2
Comments
JoCodes 25-Nov-13 11:05am    
Have you debugged the returnedLevel value matching the condition?put a else( instead of else if ) block in the end and try a redirect there just to check its redirecting properly
Computer Wiz99 25-Nov-13 11:08am    
Ok. Are you saying to take out all of the else if and just have if on all the response.redirect blocks? I also have a Session on this form.
JoCodes 25-Nov-13 11:36am    
Dont remove anything. Just add a else block with a default redirection to check if the conditions are not matched .( the way we do in switch case construct )
Computer Wiz99 25-Nov-13 11:42am    
I'm not sure I follow you on where to put the else block.
JoCodes 25-Nov-13 12:11pm    
else if (returnedLevel == 31)
{
Response.Redirect("FormDPrivateForL.aspx");
}
else
{
Response.Redirect("somepage.aspx");//
}

1 solution

Hi

Try to add the parameter false to response.redirect .
 
Share this answer
 
Comments
Computer Wiz99 26-Nov-13 5:00am    
Vinodh.B, add parameter false to where? It is not clear.
Vinodh.B 26-Nov-13 5:46am    
I had clearly mentioned Read it once again .
Ex:Response.Redirect("somepage.aspx",false);
Computer Wiz99 26-Nov-13 6:14am    
Ok. By adding the parameter false to all of the Response. Redirect, it will move to the b ext abd tge next until obe is true. Right?
Vinodh.B 26-Nov-13 6:24am    
By adding True/False it will tell whether the execution of the current page should terminate or not . Just try the code and post the results .
Computer Wiz99 26-Nov-13 9:02am    
Sorry for the long wait but the same thing is happening. It just redirects back to the same page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900