Tom Gullen
Tom Gullen

Reputation: 61727

Disabling view state on specific controls

I'm about to deploy my website, but after running some tests I can see that the viewstate is far too large on each page, and it's causing one server process to soak up huge amounts of memory.

I want to disable viewstate on the controls I can disable it on, EnableViewState="false", but before I go through adding this on controls, I'm a bit confused about which controls I can disable it on.

Could anyone tell me what conditions a control can have it's viewstate disabled are?

An example:

<a id="A5" href="~/" runat="server">
    <img src="~/images/logo.png" runat="server" />
</a>

Should I disable viewstate on those two controls? They are never changed, are in essence static resources.

Upvotes: 0

Views: 341

Answers (1)

IrishChieftain
IrishChieftain

Reputation: 15253

Yes you could safely disable it on controls such as images and links.

I would start from the top town, that is, at page-level. Generally when I have finished working on a site, I will disable ViewState on all content-only pages first at page level.

Then, I'll look at working forms/app pages and disable links/images controls locally. Anything that does not need to retain its state across a postback is a candidate. GridViews are the usual offenders WRT ViewState size and I generally tend to use ListViews myself. I particularly avoid any kind of control nesting in Grids - and I bear this in mind from the moment I start to design the UI.

Upvotes: 2

Related Questions