Click here to Skip to main content
15,888,300 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello 
How to use query string with session  in asp.net
I am working on a website containing a form which must be filled by the users. In the first page, the users by clicking the register button is referred to the second page where the user will be required to complete the registration process. 
Now my question is that how can I make it possible that when a user submits the register button in the first page must be the same user in the second page, means that the same user must be displayed in the dropdown list of the second page which is done by query string? 
As an example, below are codes which may help you better understand my question  
  
Page 1

  try
            {

                con.Open();
                cmdin.ExecuteNonQuery();
                cmdin.Parameters.Clear();
                LabelSuccsessful.Visible = true;
                LabelSuccsessful.Text = "Registration was sucessfully";
              
             
                //Session["Person_TB"] = TextBox_PersonName;
                //Response.Redirect("~/EducationPersons.aspx?pid="+XXXXXX);
                
            }
            catch
            {
                LabelSuccsessful.Visible = true;
                LabelSuccsessful.Text = "Registration was failed try again";

            }
            finally
            {
                con.Close();
                con.Dispose();
            }//----------------------------------

Page 2 
       
        //---------------show the name of user
        string strcmd = "Select Person_Name from  Person_TB where Person_ID=@piid";
        SqlCommand cmd = new SqlCommand(strcmd, con);
        cmd.Parameters.Clear();
        con.Open();
        //cmd.Parameters.AddWithValue("@iid", Request.QueryString["pid"]);
        SqlDataReader dr;
        dr = cmd.ExecuteReader();

        while (dr.Read())
        {
            LabelpersWelcom.Text = "Welcome Dear";
            LabelWEduPerson.Text = dr["Person_Name"].ToString();
           // DropDownListPersonName.SelectedValue = dr["Person_Name"].ToString();

        }
        con.Close();//----
       
    }//-------end of PageLoad
Posted
Comments
AndrewCharlz 28-Nov-14 2:15am    
is it you want to populate the drop down using data from first page

Create Session Variable on Page 1.
Check Session Value on Page Load of Page 2
C#
if(Session["Person_TB"] == null)
    // Redirect To Error Page


check Session Value Before Assign Name to Label.
C#
// user can change Query String Value
if(dr["Person_Name"].ToString() == Session["Person_TB"].ToString())
  // LabelWEduPerson.Text = dr["Person_Name"].ToString();
else
 // Redirect To Error Page
 
Share this answer
 
Comments
Member 11240896 28-Nov-14 9:48am    
Tanks dear
I want to show Dropdownlist the Name of that user that Redirected from Page1 to Page2
How do it?
//cmd.Parameters.AddWithValue("@iid", Request.QueryString["pid"]);
DropDownListPersonName.SelectedValue = dr["Person_Name"].ToString();
yash agrawal 28-Nov-14 23:52pm    
DropDownListPersonName.Items.FindByValue(dr["Person_Name"].ToString()).Selected = true;
 
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