Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form that a user can fill out and click submit button to have that data to be saved into the database. At the same time the submit button also Redirects the user back to their welcome page. I have six welcome pages for six different users that are accessed by the user level in the database. When the user logs into the site, depending on their level, will be directed to the welcome page for that user. The user will then be in a Session to where they can click on different links to different forms so they can enter and submit data into the database. While in a Session, how can I get the user back to their own welcome page? I am having trouble on how to write it.

Here is the code for the form with the submit button:

C#
protected void Page_Load(object sender, EventArgs e)
    {
      TextBoxINST_ID.Text = Session["inst_id"].ToString();
    }
protected void ButtonSubmit_Click(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DepartConnectionString"].ConnectionString);
        con.Open();


        SqlCommand cmd = new SqlCommand("Insert into Table1 (INST_ID, TOTAL_REVE, INSTRUCTIO, RESEARCH, PUBLIC_SER, ACADEMIC_S, STUDENT_SE, INSTITUTIO, PHYSICAL_P, SCHOLARSHI, AUXILIARY_, HOSPITALS, INDEPENDEN, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, EXPENDABLE, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT) values (@INST_ID, @TOTAL_REVE, @INSTRUCTIO, @RESEARCH, @PUBLIC_SER, @ACADEMIC_S, @STUDENT_SE, @INSTITUTIO, @PHYSICAL_P, @SCHOLARSHI, @AUXILIARY_, @HOSPITALS, @INDEPENDEN, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @EXPENDABLE, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LONGTERMDEBT)", con);
        

        cmd.CommandType = CommandType.Text;

        cmd.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID.Text);
        cmd.Parameters.AddWithValue("@TOTAL_REVE", TextBoxTROA.Text);
        cmd.Parameters.AddWithValue("@INSTRUCTIO", TextBoxInstr.Text);
        cmd.Parameters.AddWithValue("@RESEARCH", TextBoxRes.Text);
        cmd.Parameters.AddWithValue("@PUBLIC_SER", TextBoxPubS.Text);
        cmd.Parameters.AddWithValue("@ACADEMIC_S", TextBoxAcad.Text);
        cmd.Parameters.AddWithValue("@STUDENT_SE", TextBoxStudS.Text);
        cmd.Parameters.AddWithValue("@INSTITUTIO", TextBoxInstiS.Text);
        cmd.Parameters.AddWithValue("@PHYSICAL_P", TextBoxOperM.Text);
        cmd.Parameters.AddWithValue("@SCHOLARSHI", TextBoxSFEDA.Text);
        cmd.Parameters.AddWithValue("@AUXILIARY_", TextBoxAuxE.Text);
        cmd.Parameters.AddWithValue("@HOSPITALS", TextBoxHosS.Text);
        cmd.Parameters.AddWithValue("@INDEPENDEN", TextBoxIndeO.Text);
        cmd.Parameters.AddWithValue("@OTHEREXP", TextBoxOED.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.ExecuteNonQuery();
        con.Close();
        Response.Redirect("Login.aspx");
    }
}

Here is the code for the Login:

<pre lang="c#">
protected void Button1_Click(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DepartConnectionString"].ConnectionString);
        con.Open();




        if (true)
        {
            SqlCommand level = new SqlCommand("select accessLevel, Password, INST_ID from Table22 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");
                }
                
            }
Posted
Updated 6-Nov-13 13:41pm
v2
Comments
_Damian S_ 6-Nov-13 20:42pm    
So what's the problem? The code is a bit ugly, but looks like it would do what you are after... what happens when you run it? Is it giving you the results you expected?
Computer Wiz99 6-Nov-13 21:00pm    
It is a short version. It does work as far as the submit button for the database. But the redirect is going to the Login.aspx. I want it to redirect to the welcome page for the current login user. I know I can change the redirect page to the user welcome page, but like I said before each user has their own welcome page depending on their level. Can you show the code that could see the level the current login user is and redirect them to their welcome page?
_Damian S_ 6-Nov-13 21:49pm    
Of course the redirect goes to the login - you need them to login I would assume!

If that's not what you want, and you want them to be logged in at the point of signing up, simply include similar code behind your signup page such that they are redirected as necessary... You have the code there already.
Computer Wiz99 6-Nov-13 21:57pm    
I think you are miss understood me and the code I posted. The first code at the top is for s form that the user fills out. When they are finished they click the submit button. That button also should redirect the user back to their welcome page. In order for the user to get to the form to fill it out they are already logged in.
_Damian S_ 6-Nov-13 22:41pm    
No, I have understood what you are asking. If they are already logged in, use similar code to the login page redirect behind the button on the various information capture pages.

at the login page, you can save the 'returnlevel' value in a session variable so that you can easily get the user level after saving the details then you can write an if condition to check and redirect to the appropriate page.
 
Share this answer
 
Comments
Computer Wiz99 7-Nov-13 4:06am    
Member 8622273, can you show me a code example?
Member 8622273 7-Nov-13 5:59am    
in login code add this line Session["UserLevel"] = returnedLevel; at the submit page retrieve the value like returnedLevel = Convert.ToInt32(Session["UserLevel"]); now write if condition same as in login code to redirect to appropriate page.
Ok. I think everyone is getting confused here. I have two codes in the post. I labeled them to show where the codes come from. The first code is the Button_Submit for the form that saves the data to the database. The second code is from the Login page. If you can read it right and carefully you will see where I put these lines,"Here is the code for the form with the submit button", "Here is the code for the Login", on the post so no one will be confused.
 
Share this answer
 

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