shouldn't viewstate work for this?

G

Guest

Hi I am setting a boolean value to true on a page and writing the results to viewstate
Just above the web form designer generated code I have
Dim bps_found As Boolean 'visible to this module

in a button click event I have
bps_found=true
ViewState("ps_found") = bps_found 'save value in viewstate
then a redirect to another page, passing string information.
in the page load I have
bps_found = ViewState("ps_found") 'get value from viewstate

I put a break point in the page load and noticed after the click event when
renavigating to the page the value always stays false, when it should be true.
Thanks
 
L

Lucas Tam

ViewState("ps_found") = bps_found 'save value in viewstate
then a redirect to another page, passing string information.
in the page load I have
bps_found = ViewState("ps_found") 'get value from viewstate

Viewstate is only valid for a single page - the value does not get
propogated to a second page.

Use a session variable instead.
 
B

Ben Lucas

ViewState is only used on a single page that handles postbacks. Once you
redirect to the new page, the ViewState is lost. The reason for this is that
ViewState is actually stored in a hidden input field on the HTML form. Thus,
every time the page is posted back, ASP.Net reconstructs the ViewState
object from the hidden input field. However, the new page that you redirect
to does not have this context.

If you need to get the value to the next page, you should either use a
cookie, or the session object.

Ben Lucas
Lead Developer
Solien Technology, Inc.
 
O

One Handed Man \( OHM - Terry Burns \)

If you want to persist this over sessions, you could look at IsolatedStorage
classes in the IO.ISOLATEDSTORAGE namespace.

HTH

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

Paul said:
ok thanks for the information. The page gets closed and reloaded
several times with a typical user so sounds the viewstate information would
be lost and the session variable/object should work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top