By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,704 Members | 1,122 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,704 IT Pros & Developers. It's quick & easy.

view state in previous page using cross page postback

P: n/a
Is there a way to retrieve values from the viewstate in the previouspage
using cross page postback?

Thanks!
Bill
Feb 16 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"bill" wrote:
Is there a way to retrieve values from the viewstate in the previouspage
using cross page postback?

Thanks!
Bill

Feb 16 '06 #2

P: n/a
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?

Feb 16 '06 #3

P: n/a
Yes, that is correct - sorry for not expressing it clearly.
"Giorgio" <ge*************@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
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?

Feb 16 '06 #4

P: n/a
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

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


"bill" wrote:
Yes, that is correct - sorry for not expressing it clearly.
"Giorgio" <ge*************@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
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?


Feb 16 '06 #5

P: n/a
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/lib...39(vs.80).aspx

Feb 17 '06 #6

P: n/a

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
"Giorgio" <ge*************@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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/lib...39(vs.80).aspx

Feb 17 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.