Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant hide the VIEWSTATE hidden field in ASP.NET

Tags:

c#

asp.net

vb.net

I have to hide the VIEWSTATE and EVENTVALIDATION hidden fields on my ASP.net page at RUN time.

I managed to remove the EVENTVALIDATION like so.............

<%@ Page enableEventValidation="false" EnableViewState="false" %>

But the VIEWSTATE is still there and I cant get rid of it and I need to. (hard to explain why)

Is there another way of getting rid of it?

Thanks in advance!

like image 698
Etienne Avatar asked Dec 04 '25 10:12

Etienne


1 Answers

You need to override the following methods on your page:

protected override void SavePageStateToPersistenceMedium(
object viewState)
{
}

protected override object LoadPageStateFromPersistenceMedium()
{
    return null;
}

See here : http://weblogs.asp.net/ngur/archive/2004/03/08/85876.aspx You may be able to use this code to rename the viewstate variable if you wish but i would advise against that.

Removing the runat="server" from the form will also work as others have suggested.

Without the viewstate you will be unable to use asp.net controls. You may need to rethink what you are trying to do and why you need to get rid of the viewstate section.

like image 92
SecretDeveloper Avatar answered Dec 07 '25 09:12

SecretDeveloper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!