Hello I have a small List<string>
that I want to maintain across postbacks on only ONE page. The List will not contain more than 10 items, with each item being 40 chars max (no sensitive data).
I know that similar questions have been asked, but I am somewhat ambivalent between storing this in ViewState
or Session
. I've heard that even small string values can cause the ViewState value to increase quite largely in size. I would like to iterate through the List and use Linq to query it, but would I be better off using a string[]
array, and would this List (of humble size) be okay to store in ViewState
or should I be storing it in Session
? Thank you.
Storing things in ViewState isn't a terrible idea if you don't abuse it. If the list is small and it only makes sense on one page, then go for it.
Just remember ViewState can be tampered with, so if you don't want the client to know about it, then you are golden. Otherwise store it in Session.
I would be more concerned about the scope of this List<>
. If it's limited only to this single page, then I think it is perfectly acceptable to use the ViewState
; that's exactly what it was meant for.
However if you need to persist this across multiple pages, then it would make more sense to evaluate Session
or Cache
.
I would also keep in mind if the list is different for each user, or if it could be shared amongst multiple users. In that case I would lean towards Cache
.
Finally, and I'll probably be downvoted into oblivion on this one, but you could also look at the option of storing the ViewState
in the server-side memory using the SessionPageStatePersister class.
Good luck!
OnLoggedOut
using Session.Abandon()
). It will change poer user, as I basically want to keep track of the filenames of photos uploaded by users...the thing is that users can also choose to omit certain photos that they have already uploaded, and also provide me a way to check if they are not uploading more than 10 photos - maGz 2012-04-03 23:24
Session
- maGz 2012-04-03 23:04