I need to completely disable ViewState for a .aspx page inside my web application. I have gone through different blogs and what I understand is that we must set <%@ Page EnableViewState="false" ...%>, but this is not working.
Is this enough to disable ViewState for all the controls inside the page? Or should I make any additional modifications? If so, please specify them. I don’t want the ViewState enabled for even a single control inside the .aspx page
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Disabling View State
- Machine Level –
Disabling view state at machine level in machine.config, will disable ViewState of all the applications on the web server.
<Machine.config>
<system.web>
<pages enableViewState="false" />
</system.web>
</Machine.config>
- Application Level –
You can disable ViewState for all pages in/web.configfile.
<configuration>
<system.web>
<pages enableViewState="false" />
</system.web>
</configuration>
- Page Level –
Disabling view state for a specific aspx file at the top.
<%@ Page Language="C#" .. EnableViewState="false" .. %>
- Control Level – You can disable ViewState for a specific control.
<asp:TextBox EnableViewState="false" ID="Name"
runat="server"></asp:TextBox>
Method 2
I think the quotes should be:
EnableViewState="false"
Apart from that, if you are still seeing the hidden fields then they are used by ASP.Net. You may see:
Even if EnableViewState is false, the page might contain a hidden view
state field that is used by ASP.NET to detect a postback.
Method 3
If you truly don’t need postback, you can remove the form element from your page, this will remove the viewstate entirely.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0