Home > Interview Questions > ASP.NET > What is the use of viewstate in asp.net?

What is the use of viewstate in asp.net?

by Thamil   on 04/10/2015   Category: ASP.NET   |  Level: Intermediate   |  Views: 899    |  Points: 25     |  Gold 

View state is one of the useful client side state management method and used to preserve page and controls values between pages round trip to the server. Viewstate information’s are stored in hidden fields and APS.NET pages provide a built in view state property which allows user to automatically store the page values in view state while post back. It’s a nice feature to keep values between pages post back to the server without storing them in

Viewstate is performance overhead suppose if we store large amount of data in a web page, there is a possibilities to trap the view state data.
If you want to use viewstate then size of data should be small and avoid storing the secure data in view state.

Below is the sample code to store values in viewstate:
ViewState["UId"] = txtName.Text;

Enabling viewstate for the page in page directive:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" EnableViewState="true" Inherits="samples.test" %>

Web.config level setting:
Below setting will apply for all pages.
<pages enableViewState="true"></pages>

« What are different types of session state in asp.net?
» What is outputcache directive in asp.net?
Post Question  |  Question Home

Recent Posts

User Responses

No response found, be the first to review this question.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts

1 ??????? ?? ????? New! Forum