Technical Training
ASP.NET 2.0ASP.NET State Management Page - 2
ASP.NET State Management
Implementing the control state:
The implementation of the control state is prerogative of the programmer. The process may be as complex as implementing serialization and deserialization for the control’s state or a mere tweaking of the control’s code to achieve optimal performance in the context of usage. The initialization and loading of a controls private state has to be done in three steps:
- Override the OnInit method and invoke the System.Web.UI.Page.RegisterRequiresControlState(System.Web.UI.Control) method to register with the page for participation in control state.
- Override the SaveControlState method to save data in control state.
- Override the LoadControlState method to load data from control state.
Let us assume that we want to create a button called IndexButton. The custom control saves its state both in the control state and the view state. The IndexButton derives from the Button class and defines an Index property that is saved in control state. The IndexButton also defines an IndexViewState property that is stored in the ViewState dictionary.
Click here to view sample code
Now let us test this in the default.aspx page. Let us disable the view state by setting the EnableViewState attribute of the page to false in the page directive. In the Page_Load event handler let us add the value of the Index and IndexInViewState property in the IndexButton control. It must be noted that since the Index property is stored in the control state(and cannot be disabled), it maintains its value on postback and increases by one each time the page is posted back to the server. Since the IndexViewState property is stored in the view state and is disabled for the page, the IndexViewState property is always zero.
Click here to view sample code
New data structures can be allocated (arrays of objects, a hashtable or a custom type) and filled with the private properties to persist across the postbacks. When the method terminates it returns this object to ASP.NET runtime. The object is then binary serialized and encoded to a Base64 stream. It follows the class used to collect the control state properties must be serializable.
It is clear that the control state features were introduced to avoid the common errors made by programmers in control development. In the next section we shall examine the session state and how it has been extended in ASP.NET 2.0.
ASP.NET 2.0
- Getting started with ASP.NET 2.0
- .NET Framework Fundamentals
- Microsoft.NET Framework Tools
- Application Development in .NET
- What's New in the .NET Framework 2.0 ?
- Introduction to Visual Studio.NET
- Installing Visual Studio.NET 2005
- Working with Visual Studio.NET Web Applications
- Whats New in ASP.NET 2.0
- Creating an ASP.NET Application
- ASP.NET Code Directory
- ASP.NET Page Object Model
- ASP.NET Server Controls
- ASP.NET Working With Master Pages
- ASP.NET Creating Content for Master Page
- ASP.NET Referencing Master Page Members
- ASP.NET Changing Master Pages Dynamically
- ASP.NET Creating Nested Master Pages
- ASP.NET Working with Web Parts
- ASP.NET Using Web Parts and Controls in Web Pages
- ASP.NET Web Pages and Layout
- ASP.NET - Adding Web Parts at Run Time
- ASP.NET Personalization: User Profiles and Themes
- ASP.NET Data Access features
- ASP.NET State Management
- ASP.NET Customizing the Session State Mechanism
- ASP.NET State Management And Caching
- ASP.NET Security
- Forms Authentication in ASP.NET
- ASP.NET Managing Membership and Roles
- ASP.NET Configuring Page-Level Caching
- ASP.NET Setting Application-Level Caching
- ASP.NET Data Source Object Model
- ASP.NET SqlDataSource Control
- ASP.NET Data Bound Controls
- ASP.NET GridView Control
- ASP.NET GridView Filtering
- ASP.NET Adding Sorting and Paging in GridView
- ASP.NET DataBound Controls - Details View
- ASP.NET Using a Grid to Display Detail Information
- ASP.NET Displaying Master-Detail Data on the Same Page
- Displaying Master-Detail Data on Separate Pages in ASP.NET
- ASP.NET Creating Web Wizards
- ASP.NET : Dynamic Image control
- ASP.NET Advanced Site Functionality







