How can I get rid of:
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="..."/>
Completely !
ViewState can be easily disabled for a particular control by setting EnableViewState property to False. ViewState can be disabled for the whole Page i.e. all controls on the Page by setting the EnableViewState property to False in the @Page Directive.
In the <% @page... directive at the top of the page, add EnableViewState="False". That will prevent the ViewState for that particular page.
View state enables a server control to maintain its state across HTTP requests. View state for a control is enabled if all of the following conditions are met: The EnableViewState property for the page is set to true . The EnableViewState property for the control is set to true .
ViewState is stored in a hidden field on the page at client side. ViewState is transported to the client and back to the server, and is not stored on the server or any other external source.
You need to add the EnableViewState="false" to the @Page directive in the Default.aspx file.
<%@ Page Language="C#" AutoEventWireup="true"
Codebehind="Default.aspx.cs" Inherits="Sample._Default"
EnableViewState="false" %>
Then, add the following code to the Default.aspx.cs file. This removes the hidden field from the generated HTML.
#region Disable ViewState
protected override void SavePageStateToPersistenceMedium(object state)
{
}
protected override object LoadPageStateFromPersistenceMedium()
{
return null;
}
#endregion
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With