Written by Contributors on October 24, 2013 in C# > Programming Definitions

View State in ASP.NET [Advantages and Disadvantages]


Get our Latest updates delivered to your mailbox!

In our previous article, we looked at What is View State in ASP.Net and now in this post, we are going to check out some of the advantages and disadvantages of View State in ASP.NET. It is a technique used by asp.net webpages to persist the changes to the state of the web-form when submitted to the server or between post backs. When a user enters some information in the form and submits to the server, all form values are cleared. Lets imagine that the form has around 15-20 fields and you submitted it to server and server comes back with a error. Now suppose if you click the back button then all the data you entered previously will be cleared and you have to enter it from the beginning. This is where the View State comes pretty handy.

View State

Image Source : stackoverflow.com

You can also check out our article on “What is State Management in ASP.NET?

When the server shows the error and if you come back to your form, then all the form values will be reappears in the form. This is because of the View State maintained by  ASP.NET, and it is also considered as one of the most important concepts of State Management Techniques. The View State indicates the status of the page when submitted to the server.

This hidden field(View State) is placed on the each file which has a <form runat=”server”> control. You can look at the view state in the source file.

Right click on the page –> select view page source. Then look at the code like this

<form name="name" method="post" action="submit.aspx" id="formID">
<input type="hidden" name="__VIEWSTATE" value="dDwtNTI0ODU5MDE1Ozs+ZBCF2ryjMpeVgUrY2eTj79HNl4Q=" />

…..some other code


We cannot read the value of the View State as it is in Encrypted format.

How to disable view state :

Asp.Net maintains the view state by default. If you want to disable view state then you can do it by setting the EnableViewState=”false” in page directive.

<%@ Page EnableViewState=”false” %>

Advantages of View State:

  • It persists the state of the page.
  • View State ensures security because it stores the data in encrypted format.
  • View State can be easily Enabled and Disabled

Disadvantages of View State:

  • Lets say your form has large number of fields, then all the values entered in the form will be saved in View State and the size of the View State will become large. It effects the page performance/speed.
  • A good hacker can get the data very easily by decoding the value of the View State. So don’t store the sensitive data in the View State.

This is the Guest post by Ranadheer Reddy. He is working as a Software Engineer and he loves to share about C#.net, ASP.NET, ADO.NET, ASP.NET MVC, javascript, jquery, html and CSS3. You can check out his personal blog : http://coding-issues.blogspot.in

{ 1 comment… read it below or add one }

sangamesh gouri October 22, 2014 at 3:36 pm

Nice explanation.


Leave a Comment

Previous post:

Next post: