Each time when page is posted to the server a new instance of the Web Page Class is created. Due to this all information associated with the page and controls on the webpage would be lost with each round trip. For Example, if user enters information into a textbox, that information would be lost in the round trip from the client device to server.
To overcome all these limitations ASP.NET includes several options that help you preserve data on both a per-page basis and an application-wide basis.
These techniques are divided into two categories:
- Client Based State Management Techniques
- Server Based State Management techniques.
Client Based State Management Techniques:
- View State
- Control State
- Hidden Fields
- Cookies
- Query Strings
View State:
This is the default way used to preserve page and control property values between round trips. The ViewState property provides a dictionary object for retaining values between multiple requests for the same page.
In general we can say it is used for storing user data in ASP.NET, sometimes in ASP.NET applications the user wants to maintain or store their data temporarily after a post-back. In this case View State is the most used and preferred way of doing that.
This property is enabled by default but we can make changes depending on our functionality, what we need to do is just change the EnableViewState value to either TRUE for enabling it or FALSE for the opposite operation.
Features:
Some of the features of view state are:
- It is page-level State Management.
- Used for temporarily data holding.
- Can store any type of data.
- It is property dependent.
Control State:
ControlState property allows you to persist property information that is specific to a control and cannot be turned off like the ViewState Property.
Features:
Some of the features of control state are:
- Defines a custom view.
- Used for enabling the View State Property.
- View State property declaration.
- Cannot be modified.
- Accessed directly or disabled.
Hidden Fields:
A hidden field is used for storing small amounts of data on the client side. In other words it is a container of some objects but their result is not rendered on our web browser. It is invisible in the browser.
A hidden field does not render visibly in the browser, but you can set its properties just as you can with a standard control.
Features:
Some of the features of hidden field are:
- Use small amount of memory.
- Direct functionality access.
Cookies:
A cookie is a small amount of data that is stored either in a text file on the client file system or in-memory in the client browser session. It contains site-specific information that the server sends to the client along with page output.
Cookies can be temporary (with specific expiration times and dates) or persistent. Cookies are further divided into two categories.
- Temporary Cookies.
- Permanent Cookies.
Temporary Cookies
Temporary cookies aren't stored in the client's hard drive permanently. It maintains user information as long as the user uses the services. It is simply the opposite procedure of a permanent cookie.
Permanent Cookies
Cookies having an expiration date are called permanent cookies. This type of cookie reaches their end as their expiration dates comes to an end. In this cookie we can set an expiration date.
Features:
Some of the features of cookies are:
- Store information temporarily.
- It is just a small sized texted file.
- Can be changed depending on requirements.
- User preferred.
- Requires only a few bytes or KBs of space for creating cookies.
Query Strings:
A query string is information that is appended to the end of a page URL. A typical query string might look like the following example:
In the URL path above, the query string starts with a question mark (?) and includes two attribute/value pairs, one called "category" and the other called "price."
Query strings provide a simple but limited way to maintain state information.
Features:
Some of the features of query strings are:
- Generally used for holding values.
- Working temporarily.
- Switch information from one page to another page.
- Increase performance.
- Use virtual and real path values URL routing.
No comments:
Post a Comment