Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running ASP.NET without viewstate turned on

We're about to start rebuilding one of our ASP.NET projects and I would like to try developing it without viestate turned on (disabled in web.config).

I know about the upsides and downsides of viewstate and generally speaking what it keeps track of in comparison to control state, however I would like to know:

  1. What are the principle development process differences? Ie how differently do you structure your Page_Load etc?

  2. Is there any functionality in the standard ASP.NET controls that really will just not work without viewstate turned on?

Also, are there any detailed articles on the workflow differences between working with and without VS?

like image 291
Kieran Benton Avatar asked Mar 02 '09 00:03

Kieran Benton


People also ask

What happens when ViewState is disabled?

If you disable ViewState, and a page needs it, the page will no longer work.

Is ViewState enabled by default?

By default, ViewState is enabled for all server controls. ViewState can be enabled and disabled in any of the following ways: Control Level. Page Level.

What is ASP.NET enable ViewState?

View state enables a server control to maintain its state across HTTP requests. View state for a control is enabled if all of the following conditions are met: The EnableViewState property for the page is set to true . The EnableViewState property for the control is set to true .

Is ViewState shared between controls?

Since each control is responsible for its own viewstate, and stores required data in it, so it can render/postback etc, it ends up that there is a lage duplication in the viewstate, since the Person control stores all the data, and then each child control stores its own data again.


2 Answers

If you are that against viewstate - why not try using the MVC framework? It may be an easier adjustment.

like image 179
rifferte Avatar answered Sep 20 '22 19:09

rifferte


Most controls like TextBoxes and DropDownLists will function perfectly well without viewstate.

I don't know of any development process issues, other than any controls or properties created or modified through code will not persist without viewstate, so you would have to recreate/modify them on a postback.

I have some very big pages with large viewstates. I did an experiment to disable viewstate for the entire project, and found (at first) no noticeable loss of functionality. Then a few little issues came up in testing, so we reinstated it. But our 300 page web app was probably 99% functional without viewstate. The issues we had were centred around datagrids - paging mainly, and dynamically created controls and other things modified by code behind, and thus not persisted without viewstate.

This is a very good article on Viewstate:

http://msdn.microsoft.com/en-us/library/ms972976.aspx

like image 39
MikeW Avatar answered Sep 19 '22 19:09

MikeW