I have a site that features some pages which do not require any post-back functionality. They simply display static HTML and don't even have any associated code. However, since the Master Page has a <form runat="server">
tag which wraps all ContentPlaceHolder
s, the resulting HTML always contains the ViewState field, i.e:
<input
type="hidden"
id="__VIEWSTATE"
value="/wEPDwUKMjEwNDQyMTMxM2Rk0XhpfvawD3g+fsmZqmeRoPnb9kI="
/>
EDIT: I tried both variants of setting EnableViewState
on page level with no luck at all:
<%@ Page Language="C#" EnableViewState="false" %>
<%@ Page Language="C#" EnableViewState="true" %>
I realize, that when decrypted, this value of the input
field corresponds to the <form>
tag which I cannot remove because it is on my master page. However, I would still like to remove the ViewState field for pages that only display static HTML. Is it possible?
The method suggested by Martin must be used very carefully; because it may cause unexpected behaviors in your pages as Martin pointed in parenthesis. I've actually experienced it. But there is another option to remove viewstate content from page safely.
This option gives you the ability to use viewstate without setting false, it also allows you to remove it from your pages. Please check the articles below:
1- http://www.eggheadcafe.com/articles/20040613.asp
2- http://aspalliance.com/72
There is a solution file zipped under the Peter's article [1] you can download. I recommend that you read the second article also referenced by Peter. This is a perfect solution to remove viewstate content from your page while using its capabilities.
In the <% @page... directive at the top of the page, add EnableViewState="False". That will prevent the ViewState for that particular page.