Search code examples
c#asp.netvisual-web-developer

I need to use multiple response.redirect in ASP.NET using C#


I'm writing a school program and I'm trying to move 3 input fields to a new page.

I can get the response.redirect to work on one field but not more.

When I click the button it takes me to the next page and only one field is brought over. Not the 3 that I'm trying to get there.

Can anyone steer my right? Thanks in advance...

Page one:

protected void btnEnterSelection_Click(object sender, EventArgs e)
{
    lblBookEntered.Visible = true;
    lblBookType.Visible = true;
    lblPurchaseType.Visible = true;
    lblBookEnteredText.Visible = true;
    lblBookTypeText.Visible = true;
    lblPurchaseTypeText.Visible = true;
    lblBookEntered.Text = "The book you entered is: ";
    lblBookEnteredText.Text = txtBoxBookTitle.Text;
    lblBookType.Text = "The book type is: ";
    lblBookTypeText.Text = drpDownType.Text;
    lblPurchaseType.Text = "The purchase type is: ";
    lblPurchaseTypeText.Text = drpDownPurchase.Text;
}

protected void btnPurchase_Click(object sender, EventArgs e)
{
    Response.Redirect("turtleDoxPurchase.aspx?bookName=" + txtBoxBookTitle.Text);
    Response.Redirect("turtleDoxPurchase.aspx?bookType=" + drpDownType.Text);
    Response.Redirect("turtleDoxPurchase.aspx?purchaseType=" + drpDownPurchase.Text);
}

Page two:

protected void Page_Load(object sender, EventArgs e)
{
    lblBookEntered.Visible = true;
    lblBookType.Visible = true;
    lblPurchaseType.Visible = true;
    lblBookEnteredText.Visible = true;
    lblBookTypeText.Visible = true;
    lblPurchaseTypeText.Visible = true;
    lblBookEntered.Text = "The book you entered is: ";
    lblBookEnteredText.Text = Request.QueryString["bookName"]; 
    lblBookType.Text = "The book type is: ";
    lblBookTypeText.Text = Request.QueryString["bookType"];
    lblPurchaseType.Text = "The purchase type is: ";
    lblPurchaseTypeText.Text = Request.QueryString["purchaseType"];

    lblCreditCard.Visible = true;
    txtBoxCreditCard.Visible = true;
    lblCreditCardChoice.Visible = true;
    rdoListCreditCard.Visible = true;
    btnSubmitPayment.Visible = true;
}

Solution

  • If I understand the problem correctly, you are trying to send three values from Page One to Page Two. In that case, you could build a Query string using the values from txtBoxBookTitle, drpDownType and DrpDownPurchase. The string should be in the follwing format:

    string queryString = "?bookName={txtBoxBookTitle}&bookType={drpDownType.Value}&purchaseType={DrpDownPurchase.Value}"
    

    Then you could append the above string to your

    Response.Redirect("turtleDoxPurchase.aspx" + queryString);
    

    Hope that helps!