Raheel Khan
Raheel Khan

Reputation: 14787

Is it possible to disable ViewState in ASP .NET?

I am using third party server-side controls on my website (Telerik RadControls for ASP .NET). The menu control has a complex structure which is bloating the size of the viewstate affecting load times. I am not aware of the details of viewstate except that it is used by the web server to keep track of control values.

Since most of the pages on my website are display only, is it possible to disable the viewstate where user input is not taken? All dynamic items are being regenerated on page load in any case.

Upvotes: 0

Views: 2867

Answers (4)

Ravi Gadag
Ravi Gadag

Reputation: 15861

If you're using asp.net 4, then you can use the ViewStateMode property to control viewstate generation for controls. ViewStateMode

If you're not using asp.net 4, then you can turn of viewstate at the page or control level.

<%@ Page Language="C#" EnableViewState="false"%> //disabling viewstate. 

http://msdn.microsoft.com/en-us/library/system.web.ui.page.enableviewstate.aspx

Upvotes: 2

robasta
robasta

Reputation: 4701

There are different ways of disabling ViewState. In your case, I would recommend disabling the viewstate on the control:

<telerik:RadMenu ViewStateMode="Disabled"

Upvotes: 1

asdf_enel_hak
asdf_enel_hak

Reputation: 7640

System.Web.UI.WebControls.CheckBox checkBox = new System.Web.UI.WebControls.CheckBox();
checkBox.EnableViewState = false;

Upvotes: 1

f2lollpll
f2lollpll

Reputation: 1007

In the top of your aspx page add the parameter enableViewstate="false" on the pages that doesn't need it. it won't disable the viewstate completely though, but reduce the size seriously

I haven't tested this, but I think it's possible..

In your Web.config file add the attribute to the pages tag instead, and then on those pages you need it enabled, add the attribute with true in the top

Upvotes: 1

Related Questions