0

I have two pages. on the first page user select some filters and press search button then user navigates to the second page. On the second page user will see a grid and he will perform some tasks there.

Now the user needs to go back to the first page on one click with out using the browser back button. since the user perform some tasks in the second page which posts backs occur user can not go to the first page from one click on the browser back button.

user also needs the state of the first page to be same as when he selects the filters and press search.

How can i achieve this?

chamara
  • 12,649
  • 32
  • 134
  • 210

2 Answers2

0

Unfortunately there is no magic trick for this. You'll have to programmatically remember the return URL and also any page state that you will need to set back up when they return.

It's not uncommon to see a querystring containing a UrlEncoded ReturnUrl parameter for this purpose. If you can manage to get everything needed to restore state in the Url then you can simply redirect back to Request.QueryString["ReturnUrl"] upon completion.

If you want to avoid the querystring you'll either need to form post it, or store the needed data somewhere separate from the current request (like Session) for retrieval later.

Jason Whitted
  • 4,059
  • 1
  • 16
  • 16
0

This might help you, not exactly the back button pressed.

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) //check if the webpage is loaded for the first time.
        {
            ViewState["PreviousPage"] = 
        Request.UrlReferrer;//Saves the Previous page url in ViewState
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        if (ViewState["PreviousPage"] != null)  //Check if the ViewState 
                        //contains Previous page URL
        {
            Response.Redirect(ViewState["PreviousPage"].ToString());//Redirect to 
        //Previous page by retrieving the PreviousPage Url from ViewState.
        }
    }
akshaykumar6
  • 2,147
  • 4
  • 18
  • 31
  • that doesn't maintain the state of the previous page, you just made a redirect to the previous, in that case when the page loads it will loose all selected filters – Zinov Nov 29 '16 at 17:26