C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




PageStatePersister class in 2.0 - To persist state on page or Session or even on Database.


Posted Date: 19 May 2008    Resource Type: Articles    Category: .NET Framework
Author: Rahul SharmaMember Level: Silver    
Rating: Points: 70



New to ASP.NET 2.0, the PageStatePersister class defines the base functionality needed to persist page state to some backing store. This class is associated with a particular Page instance and provides Load and Save methods (among other members). The PageStatePersister class is abstract, meaning it can't be used directly but rather must be extended. There are two classes that extend PageStatePersister in the .NET Framework 2.0:

HiddenFieldPageStatePersister - the default page state persisting logic. Uses a hidden form field to persist page state.
SessionPageStatePersister - stores page state in a session variable, which can be used to reduce the bloat associated with persisting page state as a form field.
You can also define your own page state persistence logic by extending PageStatePersister class, opting to persist page state to a database or to text files on the web server's file system or through some other means.
Persisting Page State to Session
The .NET Framework 2.0 includes SessionPageStatePersister class, which persists page state to session. In particular, this page state persister, when used, tracks the page state for each page visit for a user in her session store using two session variables:

__VIEWSTATEQUEUE - a Queue object that maintains the names of the session variables that maintains the page state. This object just serves as bookkeeping - it just maintains the list of session state variable names. that store the actual page state. By default, only the last nine page state instances are saved in session, but you can configured your application, raising or lowering this value. Keep in mind that a request to any page (including postbacks) constitutes a "visit", so visiting a single page and posting back eight times would add nine entries to the session state queue and nine additional session state variables.
__SESSIONVIEWSTATETicksAsBase16Number - stores the serialized page state. TicksAsBase16Number takes the number of 100-nanosecond intervals that have elapsed since midnight on January 1, 0001 and the current date and time and converts it into a hexidecimal number. Again, by default only nine of these values are stored in session at a time. Upon adding the tenth item, the oldest one is removed from session state.
In its Save method, the SessionPageStatePersister class stores the value of TicksAsBase16Number in the __VIEWSTATE hidden form field. On postback, the Load method examines the passed-back TicksAsBase16Number value and retrieves the appropriate page state from the session variable __SESSIONVIEWSTATETicksAsBase16Number.
To change the default page persistence logic from the hidden form field approach to using the SessionPageStatePersister class, you can either override the Page class's PageStatePersister property or use an adapter.

To customize the size of the page state maintained in history, which dictates how many times the user can go Back with things still working as expected, add the element to Web.config, specifying a value for the historySize attribute like so:

<configuration>
<system.web>
<sessionPageState historySize="20" />
/*This value can be changed as per need*/
</system.web>
</configuration>

The downside of using session state to persist page state is that session state is volatile. That is, it automatically is abandoned after a user's session "expires," which occurs, by default, 20 minutes after a user's last activity.





Responses

Author: Mahesh Raj    07 Jun 2008Member Level: Gold   Points : 1
This is very good information,Continue posting such useful articles.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: ASP.NET 2.0 Deployment Options
Previous Resource: Basic Questions with Answers for .Net
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use