0

I have to pass two query strings that i've entered and display them on another page.

Here is the code where i attempt to pass them.

protected void btnDisplay_Click(object sender, EventArgs e)
    {
        string vacations = Session["Vacations"] as string;
        string hobbies = Session["Hobbies"] as string;
        string classes = Session["Classes"] as string;

        lblDisplay.Text = "Your favorite vacations spots are: " + vacations + "<br />" +
        "Your hobbies are: " + hobbies + "<br />" +
        "Your IT Classes are: " + classes;

    }
    protected void btnRedirect_Click(object sender, EventArgs e)
    {
        string vacations = Request.QueryString["vacations"];

        Response.Redirect("Summary2.aspx?vacations=" + vacations);
    }

Here is where I attempt to retrieve and display them.

protected void btnDisplay_Click(object sender, EventArgs e)
{


    lblDisplay.Text = Request.QueryString["vacations"];

}

I can't figure out what I am doing wrong. When i hit the Display button on my 2nd page, nothing shows up. Which I am assuming I am not passing the information correctly.

PS The information that is trying to be passed is the session states on the stop of my code. I only need to send the vacations and the classes through the query string.

1
  • Your code doesn't quite make sense. You're taking values from the query string and re-adding them to the query string? Did you mean to take from the Session instead, like you did at the top? What does the URL look like on the second page? Is there anything after vacations=? Commented Mar 31, 2014 at 17:25

2 Answers 2

1

you need to take the vacations value from session. you're reading it from the query string on the first page.

protected void btnRedirect_Click(object sender, EventArgs e)
{
    string vacations = Session["vacations"] as string; // this line
    string classes = Session["vacations"] as string;

    Response.Redirect("Summary2.aspx?vacations=" + vacations + "&classes=" + classes);
}
Sign up to request clarification or add additional context in comments.

Comments

0

I think you want to send two parameters. (Your question is a little confused)

I hope this can help you.

So, In your webForm 1, add one button and write this small code:

Session["Vacations"] = "sample 1";
Session["variable2"] = "variable 2";
string vacations = Session["Vacations"] as string;
string variable2 = Session["variable2"] as string;
string myquery = vacations + "/" + variable2;
Response.Redirect("WebForm2.aspx?myquery=" + myquery);

In your webForm 2, In the "load" event add this code:

string data = Request.QueryString["myquery"];
string[] words = data.Split('/');
foreach (string word in words)
{
    Response.Write(word);
}

It is a way to pass two parameters between two web pages.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.