PC Review


Reply
Thread Tools Rate Thread

Disable Viewstate

 
 
MCM
Guest
Posts: n/a
 
      14th Sep 2009
I have the following in my web.config file (in the system.web section):

<pages enableViewState="false"></pages>

Yet, viewstate is still being included on pages. On some pages it is VERY
large. I should also mention I am using a web deployment project - not sure
if that could be ignoring the web.config file.
 
Reply With Quote
 
 
 
 
Gregory A. Beamer
Guest
Posts: n/a
 
      14th Sep 2009
=?Utf-8?B?TUNN?= <(E-Mail Removed)> wrote in
news61DD50E-EC37-4287-A8C7-(E-Mail Removed):

> I have the following in my web.config file (in the system.web
> section):
>
> <pages enableViewState="false"></pages>
>
> Yet, viewstate is still being included on pages. On some pages it is
> VERY large. I should also mention I am using a web deployment project
> - not sure if that could be ignoring the web.config file.
>


A couple of reason I can think of off hand.

1. The web.config is in a subdirectory. This is a known issue.
2. You are using a master page that is default to true, which overrides
the setting in web.config.

I have, in the past, seen people set it up like so in either a parent
class or page, etc:

this.EnableViewState = false;

This gives more granular control. To test if viewstate is on or off,
thoughout the code, you can set a breakpoint on soemthing like:

bool testViewState = this.EnableViewState;

This can help if it is being flipped back and forth to find where it is
being set incorrectly.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

My vacation and childhood cancer awareness site:
http://www.crazycancertour.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
MCM
Guest
Posts: n/a
 
      14th Sep 2009
The web.config is in the root directory, but some controls and pages are in
subdirs. All the pages, regardless of directory, use the same Master page. If
I disable viewstate in the master page, should that work?

"Gregory A. Beamer" wrote:

> =?Utf-8?B?TUNN?= <(E-Mail Removed)> wrote in
> news61DD50E-EC37-4287-A8C7-(E-Mail Removed):
>
> > I have the following in my web.config file (in the system.web
> > section):
> >
> > <pages enableViewState="false"></pages>
> >
> > Yet, viewstate is still being included on pages. On some pages it is
> > VERY large. I should also mention I am using a web deployment project
> > - not sure if that could be ignoring the web.config file.
> >

>
> A couple of reason I can think of off hand.
>
> 1. The web.config is in a subdirectory. This is a known issue.
> 2. You are using a master page that is default to true, which overrides
> the setting in web.config.
>
> I have, in the past, seen people set it up like so in either a parent
> class or page, etc:
>
> this.EnableViewState = false;
>
> This gives more granular control. To test if viewstate is on or off,
> thoughout the code, you can set a breakpoint on soemthing like:
>
> bool testViewState = this.EnableViewState;
>
> This can help if it is being flipped back and forth to find where it is
> being set incorrectly.
>
> Peace and Grace,
>
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>
> Twitter: @gbworld
> Blog: http://gregorybeamer.spaces.live.com
>
> My vacation and childhood cancer awareness site:
> http://www.crazycancertour.com
>
> *******************************************
> | Think outside the box! |
> *******************************************
>

 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      14th Sep 2009
=?Utf-8?B?TUNN?= <(E-Mail Removed)> wrote in
news:F36CEA07-2DAA-4C93-AA50-(E-Mail Removed):

> The web.config is in the root directory, but some controls and pages
> are in subdirs. All the pages, regardless of directory, use the same
> Master page. If I disable viewstate in the master page, should that
> work?


it should. Ping back if it does not and I will see if I have some time to
play. ;-)

Peace and Grace,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

My vacation and childhood cancer awareness site:
http://www.crazycancertour.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
MCM
Guest
Posts: n/a
 
      14th Sep 2009
Strangely enough, it seemed to make the viewstate larger. If you have time,
I'd certainly appreciate your help. Thanks.


"Gregory A. Beamer" wrote:

> =?Utf-8?B?TUNN?= <(E-Mail Removed)> wrote in
> news:F36CEA07-2DAA-4C93-AA50-(E-Mail Removed):
>
> > The web.config is in the root directory, but some controls and pages
> > are in subdirs. All the pages, regardless of directory, use the same
> > Master page. If I disable viewstate in the master page, should that
> > work?

>
> it should. Ping back if it does not and I will see if I have some time to
> play. ;-)
>
> Peace and Grace,
>
>
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>
> Twitter: @gbworld
> Blog: http://gregorybeamer.spaces.live.com
>
> My vacation and childhood cancer awareness site:
> http://www.crazycancertour.com
>
> *******************************************
> | Think outside the box! |
> *******************************************
>

 
Reply With Quote
 
Allen Chen [MSFT]
Guest
Posts: n/a
 
      15th Sep 2009
Hi,

>Strangely enough, it seemed to make the viewstate larger. If you have

time,
>I'd certainly appreciate your help. Thanks.


From your description, even if ViewState is disabled, you can still see
hidden field "__VIEWSTATE", right? Based on my experience, this behavior is
normally caused by control state, which uses the same hidden field as
ViewState to persist data by default. You can refer to the following
documentation for more details:

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

We cannot disable control state. The data stored in hidden field should be
essential data for the controls to work properly.

In a word, it's normal to still see ViewState hidden field even if
ViewState is disabled. Please check if it's caused by control state. If
not, please send me a demo project that can reproduce this issue. My email
is (E-Mail Removed). Please update here after sending the project in
case I missed that email.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(E-Mail Removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
MCM
Guest
Posts: n/a
 
      15th Sep 2009
That makes sense. The more user controls I have on a page, the larger the
viewstate. So there is nothing I can do to reduce the size? It is completely
necessary?


"Allen Chen [MSFT]" wrote:

> Hi,
>
> >Strangely enough, it seemed to make the viewstate larger. If you have

> time,
> >I'd certainly appreciate your help. Thanks.

>
> From your description, even if ViewState is disabled, you can still see
> hidden field "__VIEWSTATE", right? Based on my experience, this behavior is
> normally caused by control state, which uses the same hidden field as
> ViewState to persist data by default. You can refer to the following
> documentation for more details:
>
> http://msdn.microsoft.com/en-us/library/1whwt1k7.aspx
>
> We cannot disable control state. The data stored in hidden field should be
> essential data for the controls to work properly.
>
> In a word, it's normal to still see ViewState hidden field even if
> ViewState is disabled. Please check if it's caused by control state. If
> not, please send me a demo project that can reproduce this issue. My email
> is (E-Mail Removed). Please update here after sending the project in
> case I missed that email.
>
> Regards,
> Allen Chen
> Microsoft Online Support
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> (E-Mail Removed).
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/en-us/subs...#notifications.
>
> Note: MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 2 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions. Issues of this
> nature are best handled working with a dedicated Microsoft Support Engineer
> by contacting Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>

 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      15th Sep 2009
=?Utf-8?B?TUNN?= <(E-Mail Removed)> wrote in
news:54E27039-10F5-4E51-B31A-(E-Mail Removed):

> That makes sense. The more user controls I have on a page, the larger
> the viewstate. So there is nothing I can do to reduce the size? It is
> completely necessary?


I am sure this is an "it depends" type of answer. On controls, there is
the ability to turn off viewstate, but there are instances where either
a) it cannot be done or b) it should not be done.

If you are setting up a GridView, for example, and have a lot of
maniuplation, you either need ViewState or you have to come up with your
own mechanism to reconstitute the control without viewstate.

In web apps, if you are merely displaying data (a report, for example)
you can turn off viewstate completely without a lot of consequences, as
the data is view only. This is the only place I would ever recommend
large amounts of data in a form.

On the other hand, if you are actively allowing edits, you should try to
limit the data as much as possible and use viewstate to ensure you can
reconstitute the controls on the server side.

hope this helps.

Peace and Grace,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

My vacation and childhood cancer awareness site:
http://www.crazycancertour.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
MCM
Guest
Posts: n/a
 
      15th Sep 2009
But is ControlState the same thing as ViewState? And if I want to turn off
ViewState in controls - do I have to do that in the @control directive on
each one? Or is there a way to do it globally in web.config?


"Gregory A. Beamer" wrote:

> =?Utf-8?B?TUNN?= <(E-Mail Removed)> wrote in
> news:54E27039-10F5-4E51-B31A-(E-Mail Removed):
>
> > That makes sense. The more user controls I have on a page, the larger
> > the viewstate. So there is nothing I can do to reduce the size? It is
> > completely necessary?

>
> I am sure this is an "it depends" type of answer. On controls, there is
> the ability to turn off viewstate, but there are instances where either
> a) it cannot be done or b) it should not be done.
>
> If you are setting up a GridView, for example, and have a lot of
> maniuplation, you either need ViewState or you have to come up with your
> own mechanism to reconstitute the control without viewstate.
>
> In web apps, if you are merely displaying data (a report, for example)
> you can turn off viewstate completely without a lot of consequences, as
> the data is view only. This is the only place I would ever recommend
> large amounts of data in a form.
>
> On the other hand, if you are actively allowing edits, you should try to
> limit the data as much as possible and use viewstate to ensure you can
> reconstitute the controls on the server side.
>
> hope this helps.
>
> Peace and Grace,
>
>
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>
> Twitter: @gbworld
> Blog: http://gregorybeamer.spaces.live.com
>
> My vacation and childhood cancer awareness site:
> http://www.crazycancertour.com
>
> *******************************************
> | Think outside the box! |
> *******************************************
>

 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      15th Sep 2009
=?Utf-8?B?TUNN?= <(E-Mail Removed)> wrote in
news:00C1D226-A28F-492C-B505-(E-Mail Removed):

> But is ControlState the same thing as ViewState? And if I want to turn
> off ViewState in controls - do I have to do that in the @control
> directive on each one? Or is there a way to do it globally in
> web.config?


Not 100% equivalent. I am getting a bit confused and think I might be
missing something.

Are you embedding a lot of controls in a GridView or similar?

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

My vacation and childhood cancer awareness site:
http://www.crazycancertour.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable ViewState MCM Microsoft Dot NET 4 16th Sep 2008 06:00 AM
disable ViewState ? George Ter-Saakov Microsoft ASP .NET 7 20th Jan 2007 10:34 PM
Completely disable viewstate sri_san@mailcity.com Microsoft ASP .NET 6 3rd Jan 2007 09:20 PM
Disable ViewState Julien Grossiord Microsoft ASP .NET 1 23rd Nov 2005 06:22 PM
How can I completly disable ViewState? Stan Microsoft ASP .NET 3 1st Jul 2004 01:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:17 PM.