How to Remove or Disable the ASP.NET page’s ViewState Hidden Field?

In this article I will explain with an example, how to disable or remove ViewState Hidden Field in ASP.Net Page using C# .

Problem

Even after disabling the ViewState at Page level, Master Page level or in Web.Config, still the Hidden Field of the ViewState with some amount of encrypted data is rendered on Page as shown in the figure below.

 

Solution

There is no straight forward way to disable or remove the ViewState Hidden Field.

The only possible way to remove the ViewState Hidden Field is by removing it from the generated HTML of the Page with the help of Regular Expressions.

In order to achieve the above objective, the Render event will be overridden and the ViewState Hidden Field will be removed from the generated HTML.

Namespaces

You will need to import the following namespaces.

Base Class

A new class named BasePage inheriting the Page class will be created. Inside this class, the Render event will be overridden and inside the Render event handler, the ViewState Hidden Field will be replaced with a Blank string using Regular Expressions, thus removing it from the generated HTML of the Page.

Note: The BasePage class will have to be inherited by all the Pages for which the ViewState Hidden Field needs to be removed.

The ViewState Hidden Field has been removed from the Page.

ASP.NET 10.0 Hosting Recommendation

ASP.NET is a powerful platform for creating web applications and services. You must be comfortable with JavaScript, HTML, CSS, and C# before developing a web application in ASP.NET. On the market, there are thousands of web hosting companies providing ASP.NET Hosting. But, only very few web hosting companies could provide high quality ASP.NET hosting solution.

ASP.NET is the best development language in Windows platform, which is released by Microsoft and widely used to build all types of dynamic Web sites and XML Web services. With this article, we’re going to help you to find the best ASP.NET Hosting solution in Europe based on reliability, features, price, performance and technical support. After we reviewed about 30+ ASP.NET hosting providers in Europe, our Best ASP.NET Hosting Award in Europe goes to HostForLIFE.eu, one of the fastest growing private companies and one of the most reliable hosting providers in Europe.

You may also like...

Popular Posts

Skip to toolbar Log Out