1.

What is View State?

Answer»

ViewState is used to persist the data of page or page controls on postback. Viewstates are present on a page as a hidden field with data in an encrypted format. We can store any kind of data.

Advantages:

  1. STORED only at the client side, not on the server side.
  2. Since data in ViewState is ALWAYS in encrypted form, hence secure.
  3. Viewstates can be enabled or DISABLED by viewstate properties.
  4. Viewstates can implement it at the page level or at the control level.

Disadvantages:

  1. If the size of viewstate data BECOMES large, then there might be a page load problem.
  2.   data is limited to the current page only, its information cannot be passed from one page to another.

Example:

public class Person { public string FirstName {get;set;} public string LastName {get;set;} } public PARTIAL class default : Web.UI.Pages { Person p = new Person(); p.FirstName = "Harshit"; p.LastName = "Mittal"; ViewState["PersonDetails"]=p; }


Discussion

No Comment Found