1

On a aspx page, I have to load a DropDown with some values coming from the DB. What is most correct place to put the data to keep value during the page lifecycle?

Cahce Object? Session? ViewState?

More details:

  • This data are stored inside a DataTable
  • The rows can be also 200
  • The data are all string used to filted gridView items
2
  • 2
    How long is the data valid for? The page lifetime? The session lifetime? The application lifetime? Answer that question and you have your answer :) Commented Jun 18, 2012 at 12:36
  • 1
    When are you loading the items? ASP.NET will already be handling persistence of the data (using ViewState) unless you're injecting them client-side? Commented Jun 18, 2012 at 12:37

2 Answers 2

2

Cache if the data is expensive to obtain and is the same for all users.

Session if the data is expensive to obtain and depends on the user

Nothing if the data is cheap to obtain.

ViewState if the data is in an admin page or somewhere where the traffic does not matter (internal website, rarely accessed page). 200 rows is probably a bit too much though.

Sign up to request clarification or add additional context in comments.

4 Comments

Data differ from user to user and are pretty expensive to get, but they are took from the source only one time (page load)
If the page is rarely visited or the project is deployed in an internal network go for the ViewState. BTW you can use Cache with per user data but you have to base the key on the user id or username in some way. I am not sure if session is better than cache in this case. It depends on the flow of the UI and your ability to reliably clear the session variable (because it will not expire if the user is active on the site)
Definetly full control on the Session Object. I choose session, also because this data to store somewhere belong to only on page. So in the the page load I can deal with it.
BTW if the data can be different on different requests by the same user you should make sure the user has no reason to open the page twice (in different tabs) because this could mess up the data.
1

If the data changes infrequently, Caching it is a good idea. If it changes regularly, then I would not (because you'll be frequently clearing and reloading the cache, which is a waste).

saving it per-session or in viewstate doesn't buy you much performance gains, since those are couched in a user's request. I loathe viewstate, but if you can't cache as I mentioned above, viewstate is the most appropriate place.

1 Comment

Data can change on every page re-laod and are non common to all user. Why do you loathe viestate?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.