Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
we can store generics in viewstate
Posted
Comments
Raul Iloc 31-Oct-14 7:42am    
I just improved my solution with some example.

1 solution

1.View state is a cache for storing temp data between postbacks.

2.The data are stored/get from there based on a given unique key.

3.You can store any object inside it, even that object is created by using generics, but when you get the data from the cache you must convert it to its real type like in the next example:
C#
//Supposing that you have a generic list
GenericList<T> myList;
myList = new new GenericList<MyClass>();
//.. code to populate the list
//...
//Caching the list into the view state.
ViewState["MyGenericList"] = myList;
//...
//Getting the cached data from the view state.
var myData = (GenericList<MyClass>)ViewState["MyGenericList"]; //Must use conversion!
 
Share this answer
 
v2
Comments
Thanks7872 31-Oct-14 6:22am    
Answer to even such a point less question? And IMO, this is not even a question.
sashkhdr 31-Oct-14 7:19am    
ok tell yes or no
we can store generics in viewstate
Thanks7872 31-Oct-14 7:21am    
This is not a question.
Raul Iloc 31-Oct-14 7:29am    
Because the originator forgot to put the question sign, this doesn't mean that is not a question!
sashkhdr 31-Oct-14 7:34am    
this question was asked in accenture

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900