Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

i have a website with multi forms. each page has used viewstates and different session variables and + some hidden values which are used for doing insert / update validation and operation. now when user redirect to next page does it auto clear the viewstate/session variables.i think we manually need to clear session variable but no idea about viewstate.

main concern is that in some pages a complete dataset or datatable with almost 1000 of rows are stored in session and i think this will affect the site performance.

can someone please help me.
Posted

1.The Viewstate is a cache saved into the Web Page itself, is used mainly to preserve data between page postbacks and will be automatically lost when you redirect to other page.
2.The Session is a cache associated with each user that access a web application, so it exist at the user level for all web pages of an existing application. So in your code, you should delete the unwanted data from your Session before to redirect to other page.
Example for delete: this.Session["MyRows"]=null;

The conclusion is that the Session should be used only to keep some general parameters that are needed in all pages (like user ID and rights), or can be used to send parameters between pages- but in this case after you get the parameters you have to delete them from the Session cache!
 
Share this answer
 
v2
Comments
ravikhoda 13-Mar-14 5:26am    
okay thanks for the answer..now how to delete them from session cache??

session["unwantedvariable"] = null ;

will this work ? or something else ?
Raul Iloc 13-Mar-14 5:28am    
Yes, it will works.
Note that the Session cache is a special dictionary, and the "key" used to add (save data) must be the same when you clear the same data!
ravikhoda 13-Mar-14 5:36am    
great thanks for your help.
Raul Iloc 13-Mar-14 7:34am    
Welcome!
If the solution works you should give me a good feedback by "accepting" my solution.
Good comments provided by Raul. Just wanted to reiterate that avoid Session being used for storing Dataset which contains large number of Rows. Always remember that, Session is User specific, and if we store large data it stores and holds it separately for each User consuming the Server Resources.

This will be a huge impact when there are more number of concurrent users for the Website. Would be better to Store in a ViewState, since it will be on the Cilent Side ,wont be consuming any Server Resources and cleared once redirected to another Page . Also, Can use Cache too, which stores at Server Side, but Contains only a single Copy which will be shared across the Users and should be used if Data is not frequently changed.
 
Share this answer
 
v2
Session["Session"] = null;

this will remove session.
 
Share this answer
 

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