views:

53

answers:

2

Question:-

Page is a typical search page with few filters on it. When search for records based on filters, it shows result in Gridview. From grid view records, user can click on any record to see the details which takes the focus on new page. Its working fine so far. Now when user comes back from details page to search page. I am loosing selected filters values and no result in grid view. How can i display selected filters and its results in gridview when user is coming back on search page? Any example etc.?

FYI, I am using sessions to pass parameters to the ObjectDatasource.

+1  A: 

Store the search parameters in either a cookie or a session variable. When the user returns to the search screen, use those parameters.

Chris Lively
+1  A: 

If you're losing the values when you return to the search page, I assume your having the user navigate to the search page via a link, menu, etc.? In this case when the URL is loaded in the browser the search page loads for the first time (expected behavior).

You have a few options to persist the information:

1. Session: When the initial search form is filled out and the page posts back, persist/store the form values in session. Then modify the page such that it looks for those session values on initial load and binds the grid. This would allow the values to persist.

Loose Example:

protected void btnSearchButton_Click(object sender, EventArgs e)
{
    //store the values of the form in session
}

protected void Page_Load(object sender, EventArgs e)
{
    if(!Page.IsPostBack)
    {
        //check if the values are in session. 
        //If so, remove them and use them to bind the grid.
    }
}

The only issue with the above is that you will lose client-state in your grid, so if the grid has paging, etc. and the user was on page 4 originally, when the above binds it'll be back on page 1. You could get around this by also storing state information in session when the user clicks a link in the grid (assuming the grid causes a postback and not a direct client-side navigation to the details page). You could store page #, sort column, etc. and apply these when the user returns.

2. History/Javascript: If the navigation structure of your search -> details pages is such that you have a 'back to search' link on the details page, and you are confident that the only time the details page is loaded is through search -> details, then you could rely on javascript to step back one step in history. I believe the browser would then retain the state of the previous page (the search page) and allow the user to continue using it.

Loose Example (details page markup):

<a href="#" onclick="history.go(-1);">Return to Search Page</a>

or

<a href="javascript:history.go(-1);">Return to Search Page</a>

The above is untested but in theory may work. It would allow the user to click the link, or use the back button in their browser to the same effect. Again it would only work in theory if you have a very controlled workflow where you can guarantee the person arrived at the details page from the search page.

Just some ideas...

KP