bungpeng Posted May 30, 2003 Posted May 30, 2003 Can I use ViewState to store my object? for example, collection object? like what we can do using "Session". I was encounter problem when I use Viewstate in this case. As what I know: limitation of Session is use more server resource and timeout limited. Because I just need to keep my values in the same page, so I think about Viewstate. Quote
hrabia Posted May 30, 2003 Posted May 30, 2003 You can store any object in viewstate that is serializeable (easy saying, that can be stored as string ;-). Quote A man and a dog have an average of three legs. Beaware of Statistics.
bungpeng Posted May 31, 2003 Author Posted May 31, 2003 For me, it means Viewstate cannot object any object, just "String"? like what Cookies does? Quote
*Experts* Bucky Posted May 31, 2003 *Experts* Posted May 31, 2003 If I understand correctly, you can serialize an object, then you can encode it in a string and store it in a ViewState variable, then decode and then deserialize the string to get the object back. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
bungpeng Posted May 31, 2003 Author Posted May 31, 2003 Is it? May I know how to Serialize an object? encode it in a string? and decode and deserialize? I have no idea about that... Thank you. Quote
bungpeng Posted June 5, 2003 Author Posted June 5, 2003 Anyone can help on Serialize an object? Quote
hrabia Posted June 5, 2003 Posted June 5, 2003 (edited) Ok, your object (class) has to be set with <Serializable> attribute. Than you have to use BinaryFormater (System.Runtime.Serialization.Formatters.Binary) to serialize your object to stream (MemoryStream or whatever). Stream can be converter to byte array (ToArray) which can be saved in ViewState. Deserialization is also simple. You can read your array from ViewState, make from it MemoryStream and with BinaryFormater call Deserialize on that stream. The return object must be only casted to your class. Edited June 6, 2003 by hrabia Quote A man and a dog have an average of three legs. Beaware of Statistics.
bungpeng Posted June 6, 2003 Author Posted June 6, 2003 TQ your replied "hrabia" May I know is it practical to do so? Quote
hrabia Posted June 6, 2003 Posted June 6, 2003 It is not practicalable because in standard way the ViewState flies between server and client (so has impact on performace). When you need to save your object use Session. Quote A man and a dog have an average of three legs. Beaware of Statistics.
bungpeng Posted June 6, 2003 Author Posted June 6, 2003 But the Session will timeout.... it is my problem... Quote
JIMcFadyen Posted June 6, 2003 Posted June 6, 2003 If you need the object outside of a Session then use the Application variable. John Quote
hrabia Posted June 6, 2003 Posted June 6, 2003 Than you have to save your object in ViewState, and ViewState on server. Second way is to save your serialized object in database. Quote A man and a dog have an average of three legs. Beaware of Statistics.
bungpeng Posted June 6, 2003 Author Posted June 6, 2003 No, can't use Application because it is shared by all users... I think maybe the best way is, try not to use object.... convert my object to string, then I can either use Viewstate or Cookies.... Anyway, TQ for you guys replied.... :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.