views:

105

answers:

3

Hi everyone!.

Is it better for performance to set EnableViewState to false for all pages and just except some controls that i want to enable their ViewState ?.

And how could i do this in web.config file ?.

+1  A: 

Absolutely. Disable viewstate whenever possible. :)

Be defensive. Turn it off until you know you need it. :) Good practice in my opinion.

klabranche
A: 

Try this in the web.config under system.web

<pages EnableViewState="false" />

As for if it's better: ASP.NET doesn't make it easy when you turn ViewState off even though some of the more basic controls (e.g., TextBoxes) seem to maintain their state with or without ViewState. Your mileage may vary here, but bear in mind that you're trading performance for code complexity when you turn it off.

David Andres
Is there any problems if i disable it for all pages and then enable it for some controls. i heard that these controls will not enable view state. is that true?.
Wahid Bitar
I'm not sure. You can tell by trying it and seeing if there is a reasonably sized ViewState hidden input element rendered as part of your page. If you then you have issues with state after PostBacks, you'll know it works.
David Andres
+2  A: 

You will gain in two areas:

  • the pages will be smaller which means faster transmission both from and more importantly to the server
  • your server won't have to serialize/de-serialize as much data

The first point is probably where you will gain most though (in perceived performance that is)

Locksfree