When to Disable View State?

Jared Gotte asked on June 16, 2015 18:46

Hi,

I have been told to enable "Disable view state" under Performance in web part and web part zone settings for sake of optimizing page load times. However, I cannot find any sort of reference to which web parts should have their view state enabled or disabled. According to this article, you disable the view state if it's a read only or a listing type of web part.

What about Searching? The query parameters are stored in the URL. Should I disable view state in this case?

Are BizForms/Web Forms the only web parts which require an enabled view state?

What happens to the web parts within a web part zone if I disable the view state of a web part zone?

What happens to the widgets within an Editable Text web part of which I have its view state disabled?

Generally, should more web parts have their view states disabled rather than enabled?

Why can't I find this information anywhere?

Thanks!

Correct Answer

Jared Gotte answered on June 17, 2015 22:52

Updated June 18 in response to Brenden's second answer on June 17:

First of all, thank you Emma and Brenden for trying to answer my questions! Both of you are right but here are the answers to all of my questions (feel free to correct me if I'm wrong):

[Q]: What about Searching? The query parameters are stored in the URL. Should I disable view state in this case?

[A]: After doing some trial and error with the "Smart search dialog with results" web part, I've concluded that you should not disable the view state. The reason being that the "search mode" filter quits working. However, searching and paging still work.

[Q]: Are BizForms/Web Forms the only web parts which require an enabled view state?

[A]: After doing some testing, it doesn't appear that these web parts need view state enabled. However, they were very simple web forms. Refer to Brenden's second answer below for cases where a form would need its view state enabled to work properly.

[Q]: What happens to the web parts within a web part zone if I disable the view state of a web part zone?

[A]: All web parts within that zone disable their view state, as well.

[Q]: What happens to the widgets within an Editable Text web part of which I have its view state disabled?

[A]: I haven't tested it but I'm pretty sure their view states get disabled, as well.

[Q]: Generally, should more web parts have their view states disabled rather than enabled?

[A]: This is something that you'll discover on your own as you pour through your site checking if every web part requires view state to be enabled.

[Q]: Why can't I find this information anywhere?

[A]: I'm not sure exactly why there is no documentation on view states relating specific to Kentico. I had to investigate this stuff on my own through trial and error to learn it. The best general resource that anyone has been able to provide me is this documentation which is what I have linked in my original question. For example, where would I have learned that web parts with their Visible property set to false affect the page's view state size? Furthermore, if a web part uses a visibility macro then that affects the view state size, as well.

0 votesVote for this answer Unmark Correct answer

Recent Answers


emma zelewsky answered on June 16, 2015 20:04

Hi Jared,

I've disabled view state on nearly every web part -- typically by disabling it for entire zones. I work on news sites so most of our material is articles and listings, which don't need the view state. Once it's disabled, the reduction in bloat is remarkable -- just take a look at the page source before and after disabling the view state!

The one area you have to be careful is with any web part that relies on the user session in some way, such as the logon web parts. Also any controls on a page may need view state. There's a detailed article about view state on MSDN.

A while back, someone suggested that view state be disabled by default. Even better would be if the web parts that needed it on, had view state enable, and the rest would have it disabled.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 17, 2015 13:47

@Jared, the article you mentioned is a great reference. Any webpart with form fields, buttons or requires a postback, you should leave view state enabled.

For your specific questions, yes leave the viewstate enabled for searching because it requires a postback to retrieve data and for paging. When viewstate is disabled on controls which require it, they won't function as you'd expect and you'll notice it immediately and/or receive errors. If viewstate is disabled in the parent container, it will be disabled for the child containers so your example of a widget that requires it in an editable text webpart will not work. Generally enabling/disabling viewstate depends on the site and requirements. In Emma's case, it sounds like there isn't a lot of data entry so it makes sense to disable it on most webparts. In some of the sites I've worked on, its nearly impossible to disable any of it.

To add to what Emma stated, you can disable those system settings by default by simply going to the webpart and clicking on the System Properties tab and checking the DisableViewState property.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 17, 2015 23:56

@Jared, unfortunately, your own answers are not entirely correct.

RE: Bizforms
if you have conditions set on visibility and enabled which require a field to post back, the form will not work. If you allow the form to be edited after submission, the form will not work as expected. If you have cascading dropdowns or any dependencies on other fields on that form, it will not work without viewstate enabled.

RE widgets in editable text
I've created several widgets that allow for data entry and every one of them need viewstate enabled. Although you can't think of a reason, there are some out there which will need them. Take the Reporting widget for example, if you place a report on a page and it has parameters associated with it, those cause a postback and are required for the report to do what it needs. If someone can do it, they will.

RE Finding information about viewstate
There are many people who care about it, you just have to know where to look. Since viewstate is not a Kentico "thing" it's an asp.net "thing", I'd suggest checking out the MSDN documentation for more information on what viewstate is and how it works. Kentico is a regular asp.net website.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.