shouldn't viewstate work for this?

Discussion in 'ASP .Net' started by Guest, Jul 19, 2004.

  1. Guest

    Guest 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
     
    Guest, Jul 19, 2004
    #1
    1. Advertisements

  2. Guest

    Lucas Tam Guest

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

    Use a session variable instead.
     
    Lucas Tam, Jul 19, 2004
    #2
    1. Advertisements

  3. Guest

    Ben Lucas Guest

    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.
     
    Ben Lucas, Jul 19, 2004
    #3
  4. 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

    several times with a typical user so sounds the viewstate information would
    be lost and the session variable/object should work.
     
    One Handed Man \( OHM - Terry Burns \), Jul 19, 2004
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.