Exforsys

ASP.NET 2.0

  1. Getting started with ASP.NET 2.0
  2. .NET Framework Fundamentals
  3. Microsoft.NET Framework Tools
  4. Application Development in .NET
  5. What's New in the .NET Framework 2.0 ?
  6. Introduction to Visual Studio.NET
  7. Installing Visual Studio.NET 2005
  8. Working with Visual Studio.NET Web Applications
  9. Whats New in ASP.NET 2.0
  10. Creating an ASP.NET Application
  11. ASP.NET Code Directory
  12. ASP.NET Page Object Model
  13. ASP.NET Server Controls
  14. ASP.NET Working With Master Pages
  15. ASP.NET Creating Content for Master Page
  16. ASP.NET Referencing Master Page Members
  17. ASP.NET Changing Master Pages Dynamically
  18. ASP.NET Creating Nested Master Pages
  19. ASP.NET Working with Web Parts
  20. ASP.NET Using Web Parts and Controls in Web Pages
  21. ASP.NET Web Pages and Layout
  22. ASP.NET - Adding Web Parts at Run Time
  23. ASP.NET Personalization: User Profiles and Themes
  24. ASP.NET Data Access features
  25. ASP.NET State Management
  26. ASP.NET Customizing the Session State Mechanism
  27. ASP.NET State Management And Caching
  28. ASP.NET Security
  29. Forms Authentication in ASP.NET
  30. ASP.NET Managing Membership and Roles
  31. ASP.NET Configuring Page-Level Caching
  32. ASP.NET Setting Application-Level Caching
  33. ASP.NET Data Source Object Model
  34. ASP.NET SqlDataSource Control
  35. ASP.NET Data Bound Controls
  36. ASP.NET GridView Control
  37. ASP.NET GridView Filtering
  38. ASP.NET Adding Sorting and Paging in GridView
  39. ASP.NET DataBound Controls - Details View
  40. ASP.NET Using a Grid to Display Detail Information
  41. ASP.NET Displaying Master-Detail Data on the Same Page
  42. Displaying Master-Detail Data on Separate Pages in ASP.NET
  43. ASP.NET Creating Web Wizards
  44. ASP.NET : Dynamic Image control
  45. ASP.NET Advanced Site Functionality

Ads


Home arrow Technical Training arrow ASP.NET 2.0

ASP.NET State Management

Page 1 of 2
Author : Exforsys Inc.     Published on: 27th Aug 2005    |   Last Updated on: 18th May 2006

ASP.NET State Management in ASP.NET 2.0

In this tutorial you will learn about new features included in ASP.NET 2.0 for State Management. The Control State, differences in handling View State and Control State, Implementing the control state. Initialization and loading of a controls private state.

Ads

Web pages are constantly constructed and destroyed with round trips to the server. However, state maintenance is an essential aspect of deploying web pages on a stateless protocol such as HTTP. State management is defined as a process of maintaining state and page information over multiple page requests.

State maintenance could be a feature of a client side or a server side process. The approach to state maintenance within an application will depend on a number of factors such as sensitivity of data, storage of data, performance goals and so on. ASP.NET 2.0 state maintenance can be enforced from both the client and the server effectively.

On the client side the developer has options of View state, hidden fields and cookies. The ViewState property provides a dictionary object for retaining values between multiple requests for the same page. The Hidden field stores a variable in its value property and is explicitly added to the page. The HTMLInputHidden control provides the hidden field property to the page. A cookie is a small amount of data that is stored in the client machine or in the memory of a client browser session. It contains site specific information that the server sends to the client along with a page output. Cookies can be temporary or have specific expiration dates. Client side storage would imply weakened security and a limitation on the amount of data that can be stored but better performance.

The server side options would include Application, session and Cache. Application state is a key value dictionary structure that is created during the page request to a URL. Application specific information can be added to this structure and stored between page requests. The session state is scoped to the current browser session and the number of session states will be determined by the number of users using the application. The session can be different for each visit by the user. The Cache is a hashtable used to store frequently accessed data. It is global to the application and is visible from within each currently active session. The Cache can be accessed using the name/value properties. While session is a block of memories set aside for each user, cache manages globally accessible data. Server side storage would provide for greater security but would have issues of scalability if size of information is large.

The entire state management therefore, will have to be a balance between security and performance.

ASP.NET 2.0 has introduced several new features to help the developer.

1. Custom controls with Control state which are more reliable than View State. This control is independent of the view state and customizable.

2. Custom session state management options which are persistent in the data storage medium and a session state provider object can be created.

3. Mechanism for handling custom cache dependencies, including SQL Server database dependencies in with a feature to invalidate cache results when one of the records displayed gets updated.

The control state

All controls in ASP.NET inherit the View State property from the Control Class. The state is stored in Name/value pairs and the view state property returns an instance of the StateBag class which is a specialized dictionary object. At a level of abstraction the Control state and the View state are similar but have several differences in handling.

View State

Control State

View state is a property inherited from the control class and is inherited by all controls. It is independent of the Control’s state.

Control state is the control’s private view state. Control state is designed for storing a control's essential data (such as the page number of a pager control) that must be available on postback when view state is disabled.

View state can be enabled or disabled for an entire page or for a specific control

Control state cannot be disabled for a control.

View state is sent by the server as a hidden variable in a form, as part of every response to the client, and is returned to the server by the client as part of a postback. However, to reduce bandwidth demand when using mobile controls, ASP.NET does not send a page's view state to the client. Instead, the view state is saved as part of a user's session on the server. Where there is a view state, a hidden field that identifies this page's view state is sent by the server as part of every response to the client, and is returned to the server by the client as part of the next request. However, since the view state for a given page must be kept on the server, it is possible for the current state to be out of synchronization with the current page of the browser, if the user uses the Back feature on the browser to go back in the history.

The control state is stored in the same hidden variable as the view state. Even when view state is disabled control state travels to the client and back to the server in the page. On postback the hidden variable is deserialized and the control state is loaded into each control that is registered for the control state mechanism.

The custom control’s view state is stored by adding to a dictionary object through the ViewState property which is inherited from the Control Class. The ViewState property returns an object of the type StateBag which is a dictionary like type.

In the control state the objects are not stored in a fixed container. The data can be maintained in plain private or protected members. This makes access to data faster and is not mediated by a dictionary object.

Few server controls make private use of the view state and even in those controls the use is limited to specific features.

All controls can use the control state as it is intrinsic to the control.

If a developer wants a control to persist in its state between posts, the view state has to be used privately to store the content of non public properties. However, this will not work if the view state is disabled or the application or page level settings are changed.

The control state replaces the private use of the view state by storing the state within the control.

It is possible to control the amount of data that is moved back and forth between posts.

It is not possible to control the amount of data that is moved back and forth during posts.

The view state of the control/page is automatically initialized and restored by ASP.NET runtime

The developer has to initialize the private state of a control on loading.



 
This tutorial is part of a ASP.NET 2.0 tutorial series. Read it from the beginning and learn yourself.

ASP.NET 2.0

  1. Getting started with ASP.NET 2.0
  2. .NET Framework Fundamentals
  3. Microsoft.NET Framework Tools
  4. Application Development in .NET
  5. What's New in the .NET Framework 2.0 ?
  6. Introduction to Visual Studio.NET
  7. Installing Visual Studio.NET 2005
  8. Working with Visual Studio.NET Web Applications
  9. Whats New in ASP.NET 2.0
  10. Creating an ASP.NET Application
  11. ASP.NET Code Directory
  12. ASP.NET Page Object Model
  13. ASP.NET Server Controls
  14. ASP.NET Working With Master Pages
  15. ASP.NET Creating Content for Master Page
  16. ASP.NET Referencing Master Page Members
  17. ASP.NET Changing Master Pages Dynamically
  18. ASP.NET Creating Nested Master Pages
  19. ASP.NET Working with Web Parts
  20. ASP.NET Using Web Parts and Controls in Web Pages
  21. ASP.NET Web Pages and Layout
  22. ASP.NET - Adding Web Parts at Run Time
  23. ASP.NET Personalization: User Profiles and Themes
  24. ASP.NET Data Access features
  25. ASP.NET State Management
  26. ASP.NET Customizing the Session State Mechanism
  27. ASP.NET State Management And Caching
  28. ASP.NET Security
  29. Forms Authentication in ASP.NET
  30. ASP.NET Managing Membership and Roles
  31. ASP.NET Configuring Page-Level Caching
  32. ASP.NET Setting Application-Level Caching
  33. ASP.NET Data Source Object Model
  34. ASP.NET SqlDataSource Control
  35. ASP.NET Data Bound Controls
  36. ASP.NET GridView Control
  37. ASP.NET GridView Filtering
  38. ASP.NET Adding Sorting and Paging in GridView
  39. ASP.NET DataBound Controls - Details View
  40. ASP.NET Using a Grid to Display Detail Information
  41. ASP.NET Displaying Master-Detail Data on the Same Page
  42. Displaying Master-Detail Data on Separate Pages in ASP.NET
  43. ASP.NET Creating Web Wizards
  44. ASP.NET : Dynamic Image control
  45. ASP.NET Advanced Site Functionality
 

Comments