views:

71

answers:

5

The problem that I am having is as follows:

I currently have a custom class that generates buttons and places them on a placeholder on a master page.

The events for these buttons put specific values into session that differs values for a database query. In essence, the buttons serve as filters for charts.

After creating all the buttons, I realized that session values will stay constant from page to page, so everytime a user enters a different page while another is open, the filters selected on the open page will remain constant for the new page that is opened.

At first, I wanted to use viewstate rather than session, but then realized that a master page and a content page do not share the same viewstate.

At the current time, I am thinking of using a prefix for the sesson key that will identify what page the filters actually exist for. However, I am not wanting to overload session with numerous values if the user wishes to have many pages open at the same time.

Any solutions that would entail a way to share viewstate (or some other way to store values) between app_code, the master, and the content page?

A: 

Have you considered Context.Items?

RichardOD
+1  A: 

Use HttpContext.Current.Items, it is a key-value pair collection with a lifetime of a single Http Request.

joerage
This sounds like the right direction for my problem.However, since it only has a lifetime for a single request, would the user be able to select multiple filters and have those values persist across the different selections?
BlankenshipMQ
In the case of multiple pages, hence multiple Http Request, no, this won't work.
joerage
A: 

How many filters are we talking here? Store the filter values in the URL. Have you seen some of the URLs that google or an ecommerce site uses? They are quite long. Here is how I do it:

  1. I store the filter values in the query like, www.chart.com?filter1=val1&filter2=val2 etc.
  2. I user JQuery's query plugin to manipulate the query on the client side, and then request the chart from the server again, using the new query.
  3. This way, I'm not junking up session, cookies, or anything like that, and if the user wants to store a bookmark to a particular chart or email it to a friend, they can and the filters are preserved.
Josh Pearce
A: 

I'm starting to think the answer shown in the following question will work:

http://stackoverflow.com/questions/378381/viewstate-object-lost-in-master-page-load

Exposing the desired variables via a property.

MadMAxJr
A: 

If the data isn't too long, cookies are a typical solution.

Another option is to use Silverlight isolated storage. The Silverlight control itself could be invisible (no UI).

RickNZ