简体   繁体   中英

Back to previous page on current session

How to set the back button in detail page to refer to previous page (list of order page) that user view. On my situation, I have three page that using query string to get the page (list of order page).

aspx.cs file in list of order page:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            BindOrderList(Request.QueryString["order"]);


        }


    }

       protected void pending(object sender, EventArgs e)
    {

        Response.Redirect("OrderHistory.aspx?order=pending", true);
    }

    protected void confirmed(object sender, EventArgs e)
    {

        Response.Redirect("OrderHistory.aspx?order=confirmed", true);
    }
    protected void rejected(object sender, EventArgs e)
    {
        Response.Redirect("OrderHistory.aspx?order=rejected", true);
    }

In detail page, i have one button for user click to back on the previous page that they view. Example, if they see the confirmed order list and click on one of the order to view the detail, then on the detail page they click back button, then they should back to the confirmed order list page. Same goes to pending order list page and rejected order list page. How can I set the back button function on my situation and where i need to set , in the list order page or in detail page?

Use Session object to save URL for the same page when user click for details page. When he/she hit back button, the call goes to the server and you can fetch the URL from Session and redirect to the same page.

protected void pending(object sender, EventArgs e)
{

    Response.Redirect("OrderHistory.aspx?order=pending", true);
    Session["ReturnURL"] = "OrderHistory.aspx?order=pending";
}

protected void confirmed(object sender, EventArgs e)
{

    Response.Redirect("OrderHistory.aspx?order=confirmed", true);
    Session["ReturnURL"] = "OrderHistory.aspx?order=confirmed";
}
protected void rejected(object sender, EventArgs e)
{
    Response.Redirect("OrderHistory.aspx?order=rejected", true);
    Session["ReturnURL"] = "OrderHistory.aspx?order=rejected";
}

So on page OrderHistory.aspx.cs code-behind there is event-handler for Back button like

 protected void btnReturnBack_Click(object sender,EventArgs e)
 {
      //Code for whatever you want to done here
      if(Session["ReturnURL"] != null)
      {
           Response.Redirect(Convert.ToString(Session["ReturnURL"]), true);
      }
 }

Hope this will resolve your query.

In detail page for back button, i use below code:

protected void btnBack_Click(object sender, EventArgs e)
    {
        string URL;
        URL = "OrderHistory.aspx?order="+Convert.ToString(Session["ReturnURL"]);
        Response.Redirect(URL);

    }

In list order page in page load:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            BindOrderList(Request.QueryString["order"]);



            Session["ReturnURL"] = Request.QueryString["order"];


        }


    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM