Click here to Skip to main content
Licence 
First Posted 2 Mar 2004
Views 31,185
Bookmarked 12 times

View State in ASP.Net

By | 2 Mar 2004 | Article
This articles discuss about the view state in ASP.net

Introduction

The stateless behaviour of HTTP makes it impossible to restore the form control values once a request is sent to the server. In ASP this was a major problem and we have to write code to overcome this problem. But in .NET it is handled by the page viewstate. So now in .NET the server retains the information about the previous client request, such as form fields and the state of the instantiated object.

The viewstate retains the value of most controls except the TextBox for accepting passwords, which doesn’t have this facility. The values are stored as name-value string variables, which are passed back to the client in the page.  Since the client is not aware of the viewstate this is stored as a hidden field in the form.  If you see the source for this page, you can see an input tag for which the type attribute is set to hidden followed by the name attribute and the value attribute. The value attribute is a string, which is not in a human readable format and is a combination of all values in controls. So when the page is sent back to the server the web processor reads this value and restores it in the server controls. Thus the state of the page is kept with the page itself rather than managing it in the web server. But you have to consider the performance issue in this case, as the time required to process the request is no more the same as when you don’t retain the value.

The viewstate is enabled by default for all the server controls. The viewstate can be disabled in four ways. You can disable it machine level, application level, page level and control level.

To disable it in the entire page

<%@ Page EnableViewState =”False” %>

To disable it in application level, use web.config

To disable it in control level, change the control properties

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

ManojRajan

Web Developer

United States United States

Member

I'm ManojRajan, Working as a consultant architect in Tennessee. I have more than 8 years of experience in Microsoft Technologies.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMay be usefull PinmemberDanila Korablin5:08 19 Jun '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 3 Mar 2004
Article Copyright 2004 by ManojRajan
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid