Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form that when a user logins in to their welcome page they can click on a link that will take them into another form for them to fill out. Once the form is filled out they can click submit and the code saves the data into the database and redirects the user back to their welcome page. All of the users have the same link on their welcome page. My question is how can I get the form to redirect to the current user welcome page?

C#
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing.Printing;

public partial class FTEEnrollmentInformation : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

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

        SqlCommand cmd = new SqlCommand ("Insert into TableFTE (FT_UNDERGR, FT_GRAD, FTE_UNDERG, FTE_GRAD, NON_CREDIT, TOTAL_FTE, FCFTUHC, FCFTPBHC, FCPTUHC, FCPTBHC, NCHC) values (@FT_UNDERGR, @FT_GRAD, @FTE_UNDERG, @FTE_GRAD, @NON_CREDIT, @TOTAL_FTE, @FCFTUHC, @FCFTPBHC, @FCPTUHC, @FCPTBHC, @NCHC); Insert into TableGRADRATE (ASTUDENTS, ACOMPLETED, ATRANSFERS, BSTUDENTS, BCOMPLETED, BTRANSDERS, YEAR, DATE) values (@ASTUDENTS, @ACOMPLETED, @ATRANSFERS, @BSTUDENTS, @BCOMPLETED, @BTRANSDERS, @YEAR, @DATE);", con);
        
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@FT_UNDERGR", TextBoxFTUG.Text);
        cmd.Parameters.AddWithValue("@FT_GRAD", TextBoxFTG.Text);
        cmd.Parameters.AddWithValue("@FTE_UNDERG", TextBoxTHUGDR.Text);
        cmd.Parameters.AddWithValue("@FTE_GRAD", TextBoxTHGDR.Text);
        cmd.Parameters.AddWithValue("@NON_CREDIT", TextBoxNCCDR.Text);
        cmd.Parameters.AddWithValue("@TOTAL_FTE", TextBoxTCNC.Text);
        cmd.Parameters.AddWithValue("@FCFTUHC", TextBoxTNFUG.Text);
        cmd.Parameters.AddWithValue("@FCFTPBHC", TextBoxTNFG.Text);
        cmd.Parameters.AddWithValue("@FCPTUHC", TextBoxTNCPUG.Text);
        cmd.Parameters.AddWithValue("@FCPTBHC", TextBoxTNCPG.Text);
        cmd.Parameters.AddWithValue("@NCHC", TextBoxTNNCC.Text);
        cmd.Parameters.AddWithValue("@ASTUDENTS", TextBoxTNUGSC.Text);
        cmd.Parameters.AddWithValue("@ACOMPLETED", TextBoxTNUGSCD.Text);
        cmd.Parameters.AddWithValue("@ATRANSFERS", TextBoxTTOUG.Text);
        cmd.Parameters.AddWithValue("@BSTUDENTS", TextBoxTNGSC.Text);
        cmd.Parameters.AddWithValue("@BCOMPLETED", TextBoxTNGSCD.Text);
        cmd.Parameters.AddWithValue("@BTRANSDERS", TextBoxTTOG.Text);
        cmd.Parameters.AddWithValue("@YEAR", TextBoxYEAR.Text);
        cmd.Parameters.AddWithValue("@DATE", TextBoxDATE.Text);

        con.Open();
        cmd.ExecuteNonQuery();
        Response.Redirect("FormAPublic.aspx");
        
    }
   public class PCPrint : System.Drawing.Printing.PrintDocument
    {
        
    }
   protected void ButtonPrint_Click(object sender, EventArgs e)
   {
       
   }
}
Posted
Comments
Manikandan Sekar 23-Jul-13 11:01am    
i don't believe its the correct solution for your need, but i am just saying my idea. Insert one more field in the database as Status, whenever a person logins means set his status as 'Active' or 'logged in' and based on the status redirect him to the userWelcome page and during logout set his status to 'DeActive'.
Computer Wiz99 23-Jul-13 11:14am    
Ok. I kinda get what you are saying but what will be the best code for that after it is set in the database?
Manikandan Sekar 23-Jul-13 11:20am    
Sorry i didnt get you
Computer Wiz99 23-Jul-13 11:22am    
Do you have a sample code?
joshrduncan2012 23-Jul-13 11:29am    
I strongly suggest using the TextBox.Text.Trim() commands. That'll eliminate leading and trailing spaces that a user might enter.

1 solution

during adding user set Status as Active defaultly
When the first time user signup, redirect him to login page set Status as Deactive.
When he again login means
check the status if it is active and redirect him to form page to insert data else
redirect to userWelcome page

C#
sqlcmd = new SqlCommand("select uname,status from userLoginTable where username='" + TextBox1.Text + "' and password='" + TextBox2.Text + "'", sqlcon);
               sqlReaderl = sqlcmd.ExecuteReader();

               if (sqlReaderl.Read())
               {
                   
                   Uname = sqlReaderl["uname"].ToString();
                   userstatus = sqlReaderl["status"].ToString();
                   
               }


you have got the user status, now check the status and redirect him.

C#
if (userStatus.Equals(Active))
                       {
                           string query = "update userdetails set Status='Active' where uname='" + Uname + "'";
                           sqlcmd = new SqlCommand(query, sqlcon);
                           sqlcmd.ExecuteNonQuery();
                           MessageBox.Show("Login Success");
                           Response.Redirect("Form.aspx");
                       }
                       else
                       {
                           MessageBox.Show("User Entered the data already");
                           TextBox1.Text = "";
                           TextBox1.Focus();
                           Response.Redirect("UserWelcome.aspx");
                       }


Change the flow depend upon your need.
Hope it helps
 
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