2008 aio bandwidth blade bladesystem c3000 csUriQuery csUriStem database development disposal download drive edition email express filter hosting hp IIS IIS7 isapi iscsi KB linux management memory microsoft mpio oil oracle performance proliant purification query quota recovery recycling release server solid solvent SQL sqlserver system thinner togo unlimited web windows

View State can really mess you up if you're not careful

Disambiguation 'overhead', 'overheads'

Your search yielded multiple results, here are top results:
View State can really mess you up if you're not careful


When developing complex application in ASP.NET you may end up placing hundreds of components on a single page. You may think hundreds is an exaggeration, however, when placing just couple of components on each field of a grid, the numbers will skyrocket rather quickly. With ASP.NET, any modified state of a component will be automatically persisted to a view state by default. After a few iterations of changes you may end up with very long view state that will take time both to download, and on any postback, it will also take time to upload.

How does the view state work? To put it simply by example - suppose we have a label showing number of search hits in the database. We will initialize label text to display zero. The state is not persisted. When visitor hits search button, text of label will be set to reflect three hits. This is a change to state of label and this value is now persisted in view state. When person searches for nonexistent term, they will submit the view state with the additional label overhead. If in our example number of matches is zero, the label is reset back to its original value, however, since viewstate is in effect, the value is persisted to viewstate.

In previous example, it is easy to understand why would web application seemingly slow down when in use. The view state grows and large amount of data is sent back and forth notwithstanding the fact that it is probably useless to do so. When user searches for new item, it does not really matter that label displayed "37 matches", because this state is not useful in performing new search action.

Scroll down for additional info labeled What can you do about viewstate?

More info: What can you do about viewstate?

permanent link to article http://freecash.hogger.net/view_state_can_really_mess_you_up_if_you_re_not_careful

Viewstate is your friend in some cases while in others it becomes your enemy. In both cases you can probably do without viewstate. It is up to you if you decide to almost completely abandon viewstate management and use session management instead, or if you find middle ground with limited view state. I have some suggestions and easy pointers:

Disabling viewstate

You can disable view state in many ways:

Inside your codebehind:
  MyLabel.EnableViewState = false;

Inside your asp design code:

  <asp:Label EnableViewState="false" runat="server" />

Whole page definition:

<%@ Page EnableViewState="false" %>

All pages in web.config (make sure your capitalization is correct):

<system.web>
  <pages enableViewState="false"/>
</system.web>
Multiple server farm and clusters

When deploying multiple servers, best practices call for quorum resource, such as database, to persist session states. This way, when client fails over to another server, your application can retrieve data from persistent store. In this case you do not want to burden your storage so keep what you need in view state when applicable.

Single server

On single server system, you will generally persist session state to memory. Memory is very fast and cheap resource and if your application requires stateful information, consider storing it in session state rather than traveling it back and forth between server and client on every click

Dynamic content

If your component setting is determined during page generation and if you do not need previous state of component to determine the outcome, you really do not need any state for the component whether stored in session state, cookie or view state. In these cases consider setting EnableViewState property to false.

You said viewstate can be my friend - how?

Imagine following scenario - you have local application wich requires rather complex amount of data stored in session state. The CPU load on servers is so severe that company expanded to multi server setup. Now you are really hammering at your persistent storage. You could in this case easily move large chunk of session state into view state of Page by deploying constructs such as:

ViewState[keyName] = value

2008 July Keyword Searches Page 11
2008 July Keyword Searches Page 12
2008 July Keyword Searches Page 13
FIX: You cannot use an ISAPI filter to change the uri-stem field or the cs-user field in an IIS 7.0 log
Tomcat connector isapi_redirect.dll does not handle watchdog_interval properly when not initialized or set to zero (off)
Radically speed up your ASP.NET page
UPS (uninterruptable power supply)
USB 3.0 will bring tenfold increase in speed
Transactional Memory and Intel STM compiler - how does it work
IIS7 on Vista and 2003/2008 Server various versions