views:

370

answers:

3

I have a web application that allows a user to search on some criteria, select an object, edit it and then return to the previous search. All the editing takes place on a separate page linked to the datagrid of returned results. I was wondering what is the best way to store the previous search parameters so that when they return to the grid they have the same search they previously used. The best option I came up with is to use a NameValue collection of each of the selected paramters and store that to Session or a cookie when the user presses the search button. Any other ideas as to a better way to approach this?

A: 

you could have all of the changes made in a popup and then you would not have to worry about saving all of the search criteria

jmein
You would just need to refresh the underlying page.
mattruma
@Matt if you make your own popup you could edit the underlying page to have the results directly
jmein
A: 

In our app, we have dozens of lists with search fields. We've designed a simple utility class that generates a unique string based on the current Page and stores it in the session.

 public static string GenerateSessionKeyFromPage(Page page)
 {
  return "__" + page.Request.Path;
 }

This allows us to store the search field without having to maintain a NameValue collection every time we add a new page.

Jason Kealey
+1  A: 

If it's a common query (common across all users), you may want to cache the results and simply bind to the cached results when you return to the grid. It'll save you the processing and bandwidth expense of making the call again.

If it's a user-specific query and you have the resources, you may want to cache the results.

If it's a user-specific query and you don't have the resources, caching the parameters (like you mention) is probably the best option.

Coming up with a robust caching scheme can be tricky. Take a look at memcached to see how others have solved it (note the ASP.NET Memcached Providers).

Corbin March