BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Disabling View-State Made Simpler in ASP.NET 4.0

Disabling View-State Made Simpler in ASP.NET 4.0

Leia em Português

This item in japanese

ASP.NET 4.0 offers a new mechanism to enable/disable the view-state, controlling it becoming much easier than before. To store their state, ASP.NET controls have used view-state, enabled by default until now. This behavior resulted sometimes in large amounts of data being transferred between the client and the server.

The whole concept of view-state in ASP.NET is thoroughly covered in the blog post Truly Understanding Viewstate, by Dave Reed back in August 2006 and is recommended reading for all developers working on the ASP.NET platform. As Dave points out, “ViewState is a very misunderstood animal”, and should be used with care. Developers that have not experienced how view-state works, have sometimes been surprised when looking at the HTML returned to the client browser. If one is not conscious of how view-state is used, the size of the page returned to the user can be extremely big, resulting in potentially low performing websites.

At PDC2008, Scott Hunter, Program Manager for ASP.NET, talked about the ASP.NET 4.0 roadmap. In his talk he explained how view-state is changed in 4.0:

We’re going to give what we call granular control of view-state. Which means you can turn it off at the page, and just turn it on for the controls you want. Versus turning it on, and turning it off a million places. So it should be much easier to say: I want it off for the page, turn it on for these three controls, and it’s out of your way.

To summarize, this allows to:

  • Disable on page, enable on specific controls
  • Disable on control, enable on child controls

Also GridView/ListView is promised to work better without view-state.

Scott was asked if view-state would be disabled by default during an interview done by getpixel8ed.com’s podcast, also recorded during PDC2008:

That’s up in the air. I would like to make it the default. Maybe it will be if you build a 4.0 application it’s off by default, while obviously if you’re doing multi targeting and doing 3.5 or 2.0 app you’re going to get the original behavior.

Scott’s complete PDC talk on ASP.NET roadmap contains more information on the changes to come in ASP.NET 4.0.

Rate this Article

Adoption
Style

BT