How do we access view state value of this page in the next page?

 Posted by ArticlesMaint on 9/17/2009 | Category: ASP.NET Interview questions | Views: 6718

View state is page specific; it contains information about controls embedded on the particular page. ASP.NET 2.0 resolves this by embedding a hidden input field name, __POST BACK. This field is embedded only when there is an IButtonControl on the page and its PostBackUrl property is set to a non-null value. This field contains the view state information of the poster page. To access the view state of the poster page, you can use the new Previous Page property of the page:

Page poster = this. Previous Page;

Then you can find any control from the previous page and read its state:

Label poster Label = poster. find Control ("my Label"); string lbl = poster Label. Text;

This cross-page post back feature also solves the problem of posting a Form to multiple pages, because each control, in theory, can point to different post back URL.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response