Last post Sep 28, 2011 11:39 AM by Jason Duncan
Sep 28, 2011 10:03 AM|Jason Duncan|LINK
I have 7 aspx pages that display various data. Each page has data filters (ie, dropDowns) so the user can fine-tune the data displayed (ie, location, employee, category, status, etc.)
I want to persist/preserve these settings so that during a session, the selected filters retain their values.
Right now, I am using Session variables for this storage. So I have about 42 session variables for all this info.
Is this the best way? Or should I use ViewState or Cache?
Any insights would be greatly appreciated.
Sep 28, 2011 10:15 AM|fayaz_3e|LINK
Do you have same filter in all pages? If yes, have this data filter in user control and refer them in all pages.
Having 42 session variables isn't a good practice. Why don't you merge them and have a single value in state management.
For persisting small data in same page ViewState is better. So In your case I prefer ViewState rather than session or cache.
Try something like...
//Adding filter data
Dictionary<string, string> filterValues = new Dictionary<string, string>();
//Saving its state
ViewState["FilterValues"] = filterValues;
//Retrieving from viewstate
Dictionary<string, string> viewStateValues = (Dictionary<string, string>)filterValues;
Sep 28, 2011 11:39 AM|Jason Duncan|LINK
Great idea, Fayaz! Thanks, I'll merge them all into the page ViewState.