Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top