EnableViewState = false not working

D

Dave Verwer

Hi

I have a problem which is easily reproducable using VS.NET 2003 and the .Net
framework 1.1 (not tested with framework 1.0) regarding disabling ViewState
for dynamically created controls.

Basically setting EnableViewState=false on controls created dynamically does
not stop the viewstate being stored! I have tried this at the control level
(setting EnableViewState = false for every control), at the Page level with
the @ Page directive and also at the application level in web.config and
nothing reduces the size of the viewstate. I have double checked with
ASP.NET tracing that it is the viewstate for the controls I am creating and
have confirmed this by looking at the Control Tree section which gives
viewstate size information as well as actually measuring the size of the
VIEWSTATE variable in the View Source of the compiled page.

To reproduce this problem, create a new blank web form and drop a Panel
control on it (Panel1). Then on the Page_Load event handler put the
following code:

CheckBox oCheck;
for(int i=0; i<100; i++) {
oCheck = new CheckBox();
oCheck.ID = "cb" + i.ToString();
oCheck.EnableViewState = false;
oCheck.AutoPostBack = true;
Panel1.Controls.Add(oCheck);
}

This creates 100 checkbox controls, switches the view state off and postback
on, gives them a name and adds them into the panel on the form. If you
compile and run this example, it contains 704 bytes of viewstate
information.

Then, modify the code so that the line reads:
oCheck.EnableViewState = true;

When the application is rebuilt and executed, the page still contains 704
bytes of viewstate information.

What am I doing wrong?

Thanks in advance
Dave Verwer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top