90 likes | 204 Vues
In ASP.NET, ViewState is a crucial feature that maintains page state across postbacks, but it can lead to significant performance issues due to its potentially large size, often ranging from 300K to over 1000K. This can slow down data transfer between the server and client. While ControlState serves a similar purpose for control-specific data, it's essential to find efficient storage solutions outside the hidden form field element to enhance performance. This podcast discusses strategies for managing ViewState and ControlState, including leveraging web servers, databases, and custom serialization techniques.
E N D
ASP.NET Page State Wallace B. McClure Scalable Development, Inc. ASP.NET Podcast http://www.aspnetpodcast.com/
State • ViewState • ViewState is the mechanism in ASP.NET to keep page state between postbacks. • Used to cause page level events such as button clicks. • Hidden form element – default. • ControlState • Control State data specific to a control • Separate from ViewState.
Problem • ViewState size can be rather large. If it is sent between the server and client, it can significant take time to transfer the data. • 300K-500K-1000K is not uncommon. • Turning off ViewState can break controls with special state needs, thus ControlState is separate from ViewState.
Solution • Store ViewState/ControlState someplace besides a hidden formfield element. • Alternative locations: • Webserver – How do you handle a webfarm? • Database • Problems: • Cleanup. • Back button. • AJAX.
Load/Save Data • Inherit from the PageStatePersister. • Override Load()/Save()
State() • Obtain ViewState/ControlState. • Save to a Pair object. • Serialize the Pair to a string. • Save the string. • Register the unique identifier. • PK in a database. • Filename in the file system.
Load() • Read the unique identifier. • Cleanup old values. • Obtain the serialized pair object. • Deserialize the pair. • Set the ViewState/ControlState properties.
Final Thoughts • Deleting the previous value destroys the back button functionality. • Deleting old values. • Uncontrolled growth. • What happens with AJAX calls.