Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have different users on different levels. When a user logs in they are directed to their home page or welcome page. There they can click on a link to go to a different page and fill it out. Once the form is filled out the user clicks on submit and the data is saved and the user is redirected back to their welcome page. I am trying to get the different users to redirect to their own welcome page. Right now I have them to redirect to the same page they just filled out. Is it possible to do this with different levels for users?

Here is the code I have so far:

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");
                }
                
            }


I will put this at the bottom of the code I have for saving the data.
Posted
Comments
Tom Marvolo Riddle 22-Nov-13 7:16am    
If i missed something let me know.I'll try to help you
Computer Wiz99 25-Nov-13 10:10am    
Jas24, I have a new code and question up about the redirect problem.
Computer Wiz99 22-Nov-13 8:04am    
Thanks. In the solution, would I use else if? What in my code do I not need?
Tom Marvolo Riddle 22-Nov-13 8:09am    
trysomething like this

if(returnedLevel == 1 && status ==1)
{
Response.Redirect("Public.aspx");
}
Computer Wiz99 22-Nov-13 9:00am    
You said maintain a status column for levels in sql right. How would I do that in sql? I mean the code in sql. I do have a column name level to keep the level for all the users.

1 solution

Yes it is possible.

Maintain a status column for levels in sql.
For eg.
when user level is public insert status as 1,private as 2 and so on.Then get the value from table

check this like you did it in your question
C#
if(status==1)
{
Response.Redirect("Public.aspx")
}
if(status==2)
{
Response.Redirect("private.aspx")
}
 
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