Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

view state in previous page using cross page postback

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bill - 16 Feb 2006 19:02 GMT
Is there a way to retrieve values from  the viewstate in the previouspage
using cross page postback?

Thanks!
Bill
Peter Bromberg [C# MVP] - 16 Feb 2006 19:25 GMT
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.

The field contains the view state information of the poster page.

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;

Peter
Signature

Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com

> Is there a way to retrieve values from  the viewstate in the previouspage
> using cross page postback?
>
> Thanks!
> Bill
Giorgio - 16 Feb 2006 19:53 GMT
I think that what Bill wants is a way to access the viewstate on the
previous page so if you add any items to viewstate i.e
viewstate.add("whatever", "somedata") and then retrieving on the next
page the viewstate("whatever")...
Is that right Bill?
bill - 16 Feb 2006 21:23 GMT
Yes, that is correct - sorry for not expressing it clearly.
>I think that what Bill wants is a way to access the viewstate on the
> previous page so if you add any items to viewstate i.e
> viewstate.add("whatever", "somedata") and then retrieving on the next
> page the viewstate("whatever")...
> Is that right Bill?
Peter Bromberg [C# MVP] - 16 Feb 2006 23:12 GMT
Ah. Haven't found a way to do that.

Controls and their state, yes. The actual ViewState collection, no.

Of course, remember that ViewState is not designed for cross-page
operations. You can use Session, Cache, Application, or the HttpContext Items
collection for things like that, depending on which is appropriate.

Peter

Signature

Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com

> Yes, that is correct - sorry for not expressing it clearly.
> >I think that what Bill wants is a way to access the viewstate on the
> > previous page so if you add any items to viewstate i.e
> > viewstate.add("whatever", "somedata") and then retrieving on the next
> > page the viewstate("whatever")...
> > Is that right Bill?
Giorgio - 17 Feb 2006 20:15 GMT
Ok Bill, i found it for you! You cannot do that. Here is the Microsoft
note about what you want

"If the source and target page are in different applications, you
cannot directly get the values of controls on the page, but you can
read the posted data from the Form dictionary. You cannot read view
state from the source page, because it is hashed. If you want to store
values in the source page and make them available in a target page in
another application, you can store the values as strings inside hidden
fields on the source page and access them through Request.Form on the
target page."

http://msdn2.microsoft.com/en-us/library/ms178139(vs.80).aspx
bill - 17 Feb 2006 20:32 GMT
I think I remember reading that, but thinking that they were still referring
to the source and target page being in different applications.  I thought
that because the following sentence also refers to "another application".
Wishful thinking!  I would like to use the viewstate because I have to store
a username/password and grab it in the target page, and I don't want to use
hidden fields since view source will reveal the password.  I guess I'll try
using properties.

Thanks for your help!
Bill

> Ok Bill, i found it for you! You cannot do that. Here is the Microsoft
> note about what you want
[quoted text clipped - 9 lines]
>
> http://msdn2.microsoft.com/en-us/library/ms178139(vs.80).aspx

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.