How to disable viewstate for aspx page?

2019-02-11 23:08发布

I need to completely disable viewstate for an 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. My question is, wheteher this is enough to disable viewstate for all the controls inside the page? Or Should i make any additional modifications? Please specify if any. I dont want viestate enabled for even a single control inside the aspx page

3条回答
Root(大扎)
2楼-- · 2019-02-11 23:52

If you truly don't need postback, you can remove the form element from your page, this will remove the viewstate entirely.

查看更多
戒情不戒烟
3楼-- · 2019-02-11 23:55

Disabling View State

  1. 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>
  1. Application Level - You can disable ViewState for all pages in /web.config file.
<configuration>
   <system.web>
      <pages enableViewState="false" />
   </system.web>
</configuration>
  1. Page Level - Disabling view state for a specific aspx file at the top.

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

  1. Control Level - You can disable ViewState for a specific control.

<asp:TextBox EnableViewState="false" ID="Name" runat="server"></asp:TextBox>

查看更多
萌系小妹纸
4楼-- · 2019-02-11 23:56

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:

Page.EnableViewState Property

Even if EnableViewState is false, the page might contain a hidden view state field that is used by ASP.NET to detect a postback.

查看更多
登录 后发表回答