ASP.NET webforms maintain List<string> across postbacks

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!

Need Your Help

segmentation fault 11 in mac, but not in linux, gcc compiler

linux osx gcc segmentation-fault numerical

I have a code which uses standard routines of numerical recipes for finding eigen vectors of a 3x3 matrix. While the code runs perfectly on linux machines, it fails with a segmentation fault 11 on ...

postion border image below the div

html css border

I'm trying to put a border image on the right side of div. And I've succeeded in doing that. But the problem is, I want the border image to stretch a little bit below the div. Is it possible to inc...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.