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

View State in ASP.NET [Understanding the Concept]

GET ALERTS:

Get our Latest updates delivered to your mailbox!

In this article, we are going to deal with the concept of View State in ASP.NET. This is one of the important technique under Client side State Management. View state is a Dictionary object, in ASP.Net we use this method to keep track of the values for the same request on the same page. In ASP.Net the information is encrypted as it is stored on the web page. View state does not carry values between pages , but it carries values between postback.

You might be interested in reading our previous article on “What is State Management in ASP.NET?

For Example : There is a log-in page where you have to enter in your username , password  and click on submit button. But you fill in only the username field and click on submit button(reaches the server). An error is shown and when you press the back button and go back to the last page you can still see your user name in the field, then this website is maintaining the View State. Hence View state basically shows us the status of the web page when it is submitted to the server.

Set of codes on the Default.aspx page

view state in asp.net

The following code will help us in saving the info and is written in default.aspx.cs file

Understanding view state concept

These set of codes will help us restoring the info which is also written in the Default.aspx.cs file

understanding view state in asp.net

Final output when we execute the above code,

view state concept output

After the save button is clicked, the information is restored. This is done using View State.

final output for view state

Hope you enjoyed our article on Understanding the Concept of View State in ASP.Net, we’ll be coming up with many interested topics soon.

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: