简体   繁体   中英

How can I keep my search filters when I go back to a previous web page?

I have a list of contacts and I have a couple of dropdown boxes to filter my contacts list between "vendors" and "customers".

If I select any, "vendors", "Contacts" and sort those located in "Ontario" and I have a 10 record list and I clicik one ofthe records to display all his info.

BUT now I want to go back to my 10 record list of contacts in "Ontario", how I do it to dont loose the sorted list? i dont want to start my search all over again, I wan to go back and find the 10 records form "Ontario".

Any suggestions?

You can put the search parameters in the URL, eg

http://example.com/search?select=vendors&location=Ontario

Another option is to store the last search in the session (used eg by Trac) or a cookie (used eg by Bugzilla) and re-use it if visiting the search page again. That prevents multiple searches at once, though.

If you are navigating to a differnet page for the info and you want to come back to the previous page and see the search criteria you had, you should store it in some temp storage. HTTP is stateless.So we need some temp storage locations.

You may consider storing your Search criteria in Session variable / cookies . when the previous page loads, check for session/cookies for the last search criteria you saved and load results according to that.

EDIT : A simple example using session.

public class SearchCriteria
{
  public string Type{ set;get;}
  public string Location { set;get;}
  //other properties based on your scenario
}

Then before redirecting to the new page(info page) Set the values in to the session

var search=new SearchCriteria();
search.Type="Vendors";  //hard coded for example. you may replace with your form values
search.Location="Ontario";
Session["SearchCriteria"]=search;
Response.Redirect("info.aspx?id=someId");

And in the PageLoad event of this search page, check for session

if(Session["SearchCriteria"]!=null)
{
    var search=(SearchCriteria) Session["SearchCriteria"];
    //Now load the search based on this search criteria.
    // check for search.Location/search.Type
}

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