|
-
August 30th, 2005, 12:14 AM
#1
ViewState and ViewState object
Hi guys
I fully understand what ViewState does to maintain the values1 of controls in a web form. What I would like to know is the purpose of the Session-like usage as follows -
ViewState["abc"] = "xyz";
x = ViewState["abc"];
Please tell me what is this used for.
Regards
Suhaib
-
August 30th, 2005, 05:19 AM
#2
Re: ViewState and ViewState object
Its similar to a key based map. You store the values into the ViewState collection object with a key/identifier and then when you want to retrieve a value out of it provide the corresponding key for it to search and return it to you. By the way when you retrieve the object from the ViewState or even Session you need to cast it to the relevant data type for it to be usable. For more information you could look up with a google search. Hope this helps.
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
-
August 31st, 2005, 02:18 AM
#3
Re: ViewState and ViewState object
 Originally Posted by exterminator
Its similar to a key based map. You store the values into the ViewState collection object with a key/identifier and then when you want to retrieve a value out of it provide the corresponding key for it to search and return it to you. By the way when you retrieve the object from the ViewState or even Session you need to cast it to the relevant data type for it to be usable. For more information you could look up with a google search. Hope this helps. 
Thanks for replying
So, in that case can ViewState and Session be used interchangeably ??
Or, are there any considerations ??
Regards
Suhaib
-
August 31st, 2005, 04:36 AM
#4
Re: ViewState and ViewState object
Nopes. You cannot use them interchangeably. They have very different properties and security levels. Viewstate is related to individual aspx pages whereas the Session is related to a complete session of one user. Apart from that Session variables are stored on the web server running your web application where as the viewstate is stored in a hidden field on the page. So what you want to be stored on the server should not be there with the viewstate field on the aspx page. That would cause the slow rendering of your aspx pages if the objects being stored in viewstate are larger. Better would be let the viewstate just keep the information related to the state of the controls and for all the other objects that you wish to keep alive for a user session in a session state. You could read up more about them on MSDN, some urls that i could find for you:
1. Viewstate
2. Viewstate vs Session state
You can find more with simple googling. Hope this helps. 
EDIT: Also, viewstate could only be used if your class' object is serializable.
Last edited by exterminator; August 31st, 2005 at 04:57 AM.
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|