user3531392
user3531392

Reputation: 21

disabling viewstate of whole page

Is it possible to make the viewstate false of whole page including all controls at a time.I mean I don't want to set enableviewstate="false" for all controls..In the page directive of the aspx page I have made enableviewstate="false" but still viewstate of all the controls of the is enabled..

And what the EnableViewState="False"actually works within Page directive.

Upvotes: 2

Views: 4772

Answers (3)

magnattic
magnattic

Reputation: 12998

In ASP.Net 4.0 one of the new features is more control over the ViewState of a Page and its Controls.

In ASP.Net 3.5 and earlier, the ViewState of ChildControls is ignored, if the ViewState for the Page is set explicitly. So if you set EnableViewState="false" for a UserControl, it still will use ViewState, if the Page.EnableViewState is set to true.

ASP.Net 4.0 introduces a new ViewStateMode-Property with 3 Values: Enabled, Disabled and Inherit

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" ViewStateMode="Disabled" Inherits="_Default" %>

So if you set ViewStateMode to Inherit for child controls, they will inherit the page's behaviour. If you set it to Enabled or Disabled, they will do as you want them to.

See for more info: http://www.dotnetcurry.com/ShowArticle.aspx?ID=478&AspxAutoDetectCookieSupport=1

Even though it does not directly answer your question, why your EnableViewState value in the Page gets ignored, but it might show you how to do it in ASP.Net 4.0 or where to look for the problem. Maybe you set EnableViewState="true" on a higher level, like the MasterPage?

Upvotes: 1

Oded
Oded

Reputation: 498942

This is (a somewhat dated) but still very relevant article about ViewState and how it works.

Here is another good article on MSDN.

I suggest you read and understand both before deciding that ViewState is not off.

Upvotes: 0

Merrimack
Merrimack

Reputation: 1726

Have you tried setting enableViewState to false in web.config? Like this:

<pages enableViewState="false" />

Upvotes: 1

Related Questions