Antonio Arredondo
Antonio Arredondo

Reputation: 39

How to use a session variable or cookies

I have a main page with a large list of companies, I have a search button and if I want to find a company by state or city I can filter my search.

I decide to filter my search by cities, lets say Chicago, and I get 10 companies as a result of my search.

I click any company in that list and I go to the company details but I realize that is not the one I am looking for, so I want to go back to my 10 companies result list but instead I go back to the main company search interface and I have to re-start my search again.

How to use a session variable or cookies for this case?

Somebody can help me with this?

Upvotes: 0

Views: 128

Answers (2)

theedam
theedam

Reputation: 629

I agree with Claudio, but if you do want to use session I would do something like the following

In page load do something like this

if(!Page.IsPostBack) 
{

        string filter = Session["SearchQuery"].ToString();
        if(filter  != null)
        {
            FilterResults(filter)
        } 
}

And then in your filter event do something like

Session["Filter"] = txtCityName.txt;
FilterResults(txtCityName.txt);

Upvotes: 0

Claudio Redi
Claudio Redi

Reputation: 68440

Another valid option not involving Session or cookies would be using the url for passing search parameters. If your site is public this may also help you with SEO.

You could use a friendly url + rewriting rules or just querystring if you are not using any rewriting.

On the company details page you'd store the referrer url and if the user wants to come back, you do it to that page.

Upvotes: 1

Related Questions