Reputation: 2191
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:
Upvotes: 1
Views: 140
Reputation: 23551
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.
Upvotes: 2
Reputation: 42497
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.
Upvotes: 1