Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable ViewState for a .aspx page?

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

like image 462
Mridul Raj Avatar asked Oct 03 '12 06:10

Mridul Raj


1 Answers

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>

like image 138
Johnny Avatar answered Sep 20 '22 20:09

Johnny