Click here to Skip to main content
Licence 
First Posted 20 Sep 2007
Views 12,679
Bookmarked 10 times

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

By | 20 Sep 2007 | Article
View state is page specific; it contains information about controls embedded on the page.

Introduction

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

Background

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,
__POSTBACK . 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.

Using the code

A brief description of how to use the code. The class names, the methods and properties, any tricks or tips.

To access the view state of the poster page, you can use the new PreviousPage property of the page:

//Page poster = this.PreviousPage;
Then you can find any control from the previous page and read its state: 


//Label posterLabel = poster.findControl("myLabel");
//string lbl = posterLabel.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.

Points of Interest

You can post back to any page and pages in another application, too. But if you are
posting pages to another application, the PreviousPage property will return null. This is a
significant restriction, as it means that if you want to use the view state, you are confined,
for example, to posting to pages in the same virtual directory. Even so, this is a highly
acceptable addition to the functionality of ASP.NET.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Nilesh Surve

Software Developer (Senior)
Panjim,Goa
India India

Member

Nilesh Surve
Software Engineer
Panjim,Goa
India.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberHiren Solanki1:04 14 Jun '11  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 20 Sep 2007
Article Copyright 2007 by Nilesh Surve
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid