dotnetspider.com


 


TutorialsForumResourcesReviewsJobsInterviewVideosCommunitiesProjectsTraining

Subscribe to Subscribers


Online MembersRaghu
Sankar
Lawrence
Sunitha
cloud
Rajalingam
SivaSaiKrishna
Ashokkumar
er.g.ilango
More...




Resources » Articles » .NET Framework


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


Posted Date:     Category: .NET Framework    Rating: 1 out of 5
Author: Member Level: Silver    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.


Did you like this resource? Share it with your friends and show your love!





Responses to "PageStatePersister class in 2.0 - To persist state on page or Session or even on Database."
Author: Mahesh Raj    07 Jun 2008Member Level: Gold   Points : 1
This is very good information,Continue posting such useful articles.


Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: ASP.NET 2.0 Deployment Options
    Previous Resource: Basic Questions with Answers for .Net
    Return to Resources
    Post New Resource
    Category: .NET Framework


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)

    My Profile

    Active Members
    TodayLast 7 Daysmore...


    Awards & Gifts


    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds



    About Us    Trademark Disclaimer    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.