It takes a huge time to load ViewState in the Page.
is it to make it faster.
Otherwise i have to go for Session to replace ViewState.
Hi Karthik,
Session and viewstate both have different uses and can be used based on the scenario, they do not have to be exclusive or. you could use both in a web application.
As you have allready noticed, viewstate is used only for one page and can not be accessed by a different page. Lets say that's the case
If the data you store in the viewstate is not large enough to cause performance headaches, go with viewstate, if not session is your best friend. Also, notice that session has its share of problems too. If you store too much data in session and you create
many sessions in a short period with many of your concurrent users, you would be killing your server. Remember when you use "InProc" session mode, all the session data is stored inside the application domain where your application is running, which in turn
runs inside the aspnet_wp appdomain. And it has only certain memory it can use. After that the worker process gets recycled and you would lose all the sesson data.
Ofcourse, you could use other modes of session, like StateServer mode and SqlServer mode. But they are slow compared to the "InProc" session mode
So, it depends on your scenario. There is no clear winner here.
It really depends on what you want to accomplish. I typically like viewstate for a single page, and session i use if i need a variable, object, etc over various pages (i.e. login id).
many times there is no need to have a large Session or ViewState. In fact you really want to
limit what you put in the ViewState because it can really bog you down. I have built many large applications over the years and really limit the use of either to a minimum.
What if I have a page that references a custom data source (custom provider) and I want to cache the data? (The underlying data source is XML but it must be accessed via the custom provider). No other database is involved or available for this project.
Should I use a session object for this?
The session object has to be referenced in the class to cache the returned data, which is a DataTable. The class also has to check whether search criteria selections the user can make has changed across postbacks.
As i think, Session State is useful for storing values that must be contained throughout the pages by the user. Where as ViewState is useful for storing data that must be contained or travelled across PostBacks.
I shall give an example where session plays upper hand. Suppose i want to open a child window through javascript and the child window may require some information related to parent page. In such case, i may simply put the information in session before loading
the first page and clear the session when the child window gets loaded and obtained the information from session regarding parent window. Clearing the session is very important, if data is not needed any more.
Session and View state are used for different purpose.
u can't say that session are faster then view state
session are used to access throw out the application means on different page u can use the value of session for single browser and View state used for single page. view state are saved on the Page and session are saved on Sever.
if u want to use value on same page then go with ViewState and u want to use value on different page too then go with session.
sameer.khanjit@gmail.com
View Blog Click "Mark as Answer" on the post that helped you.
aks_karthik
Participant
762 Points
162 Posts
Session Vs ViewState
May 17, 2005 10:11 AM|LINK
Hai All,
Which one is BEST to use in the Huge Web Application.
I thought,Session is faster than ViewState.
Cos i used ViewState in my Entire Project.
It takes a huge time to load ViewState in the Page.
is it to make it faster.
Otherwise i have to go for Session to replace ViewState.
Please give a brief explanation about the Both Session and ViewState.
Thanx & Regards,
Katrhik.A
Kumar Reddi
Star
14340 Points
2619 Posts
Re: Session Vs ViewState
May 21, 2005 01:50 PM|LINK
Hi Karthik,
Session and viewstate both have different uses and can be used based on the scenario, they do not have to be exclusive or. you could use both in a web application.
As you have allready noticed, viewstate is used only for one page and can not be accessed by a different page. Lets say that's the case
If the data you store in the viewstate is not large enough to cause performance headaches, go with viewstate, if not session is your best friend. Also, notice that session has its share of problems too. If you store too much data in session and you create many sessions in a short period with many of your concurrent users, you would be killing your server. Remember when you use "InProc" session mode, all the session data is stored inside the application domain where your application is running, which in turn runs inside the aspnet_wp appdomain. And it has only certain memory it can use. After that the worker process gets recycled and you would lose all the sesson data.
Ofcourse, you could use other modes of session, like StateServer mode and SqlServer mode. But they are slow compared to the "InProc" session mode
So, it depends on your scenario. There is no clear winner here.
albert_fines...
Member
10 Points
2 Posts
Re: Session Vs ViewState
Jul 30, 2006 09:27 PM|LINK
I agree. http://vbaspnet.blogspot.com/
It really depends on what you want to accomplish. I typically like viewstate for a single page, and session i use if i need a variable, object, etc over various pages (i.e. login id).
docluv
Star
12685 Points
2005 Posts
ASPInsiders
MVP
Re: Session Vs ViewState
Jul 30, 2006 09:52 PM|LINK
cool_sharad
Member
6 Points
3 Posts
Re: Session Vs ViewState
Apr 09, 2008 01:20 PM|LINK
Nice Reply.
It is really good explanation of Session and View State.
Thanks Kumar Reddi.
SHARAD KAPIL SHARMA
ASP.NET State Management
dbrook007
Member
34 Points
40 Posts
Re: Session Vs ViewState
Apr 17, 2008 03:19 PM|LINK
What if I have a page that references a custom data source (custom provider) and I want to cache the data? (The underlying data source is XML but it must be accessed via the custom provider). No other database is involved or available for this project.
Should I use a session object for this?
The session object has to be referenced in the class to cache the returned data, which is a DataTable. The class also has to check whether search criteria selections the user can make has changed across postbacks.
Is this a better option than ViewState?
e: darrenbrook@btconnect.com
Jahedx99
Member
501 Points
142 Posts
Re: Session Vs ViewState
Jun 09, 2008 06:06 PM|LINK
here is an article on session viewstate and cache
http://www.progtalk.com/ViewArticle.aspx?ArticleID=62
www.progtalk.com
tasnim5
Participant
1667 Points
277 Posts
Re: Session Vs ViewState
Jun 10, 2008 06:07 PM|LINK
Hello dear,
As i think, Session State is useful for storing values that must be contained throughout the pages by the user. Where as ViewState is useful for storing data that must be contained or travelled across PostBacks.
You Check out these articles:
http://www.codeproject.com/KB/aspnet/PTCacheSessionViewState.aspx
http://www.csharphelp.com/archives/archive207.html
Ahmed
***************************************************
Please don't forget to mark the post as Answer, which helps you.
Thank you.
www.ajtmr.com
venkyzeal
Member
154 Points
32 Posts
Re: Session Vs ViewState
Jun 10, 2008 09:37 PM|LINK
I shall give an example where session plays upper hand. Suppose i want to open a child window through javascript and the child window may require some information related to parent page. In such case, i may simply put the information in session before loading the first page and clear the session when the child window gets loaded and obtained the information from session regarding parent window. Clearing the session is very important, if data is not needed any more.
Thanks
J. Venkatesh
Syntel
sameer_khanj...
Contributor
7484 Points
1461 Posts
Re: Session Vs ViewState
Jun 13, 2008 08:59 AM|LINK
Session and View state are used for different purpose.
u can't say that session are faster then view state
session are used to access throw out the application means on different page u can use the value of session for single browser and View state used for single page. view state are saved on the Page and session are saved on Sever.
if u want to use value on same page then go with ViewState and u want to use value on different page too then go with session.
sameer.khanjit@gmail.com
View Blog
Click "Mark as Answer" on the post that helped you.