Using hidden form fields to preserve state

Discussion in 'ASP .Net' started by Mark, Feb 17, 2006.

  1. Mark

    Mark Guest

    Assume you have a web application with many different web pages, and you'd
    like to avoid using cookies and storing session state in any form. Assume
    further that bandwidth and security are not issues.

    Could you conceivably store a serialized object containing state information
    in a hidden form field, and pass it from page to page to page avoiding the
    use of cookies and session data?

    Thanks.

    Mark
    Mark, Feb 17, 2006
    #1
    1. Advertising

  2. Mark

    McGeeky Guest

    I was involved in a Java project that used this technique way back in 2000.
    We serialized our objects in to XML, embedded them in a hidden form field,
    and then desieralized when the page got posted.

    The downside was that it meant the code behind every page having to do extra
    work, also meant the pages could be quite big.

    Upside was that there was no state stored in the session.

    --
    McGeeky
    http://mcgeeky.blogspot.com


    "Mark" <> wrote in message
    news:eYYFe$...
    > Assume you have a web application with many different web pages, and you'd
    > like to avoid using cookies and storing session state in any form. Assume
    > further that bandwidth and security are not issues.
    >
    > Could you conceivably store a serialized object containing state
    > information in a hidden form field, and pass it from page to page to page
    > avoiding the use of cookies and session data?
    >
    > Thanks.
    >
    > Mark
    >
    >
    >
    McGeeky, Feb 17, 2006
    #2
    1. Advertising

  3. Mark

    Darren Kopp Guest

    Yes it's possible, just make sure that all your objects are
    serializable ([Serializable] attribute on all custom classes, then call
    the serialize method). You will also need to get the data from the
    field on the next page through Request.Form["key"] i believe.

    HTH,
    Darren Kopp
    http://blog.secudocs.com/
    Darren Kopp, Feb 17, 2006
    #3
  4. Mark,

    You will want to use hidden fields only if the information you are putting
    there is needed on the client side too. Otherwise you should use ViewState
    as an alternative to session variables.

    What do you mean by "passing from page to page"? From page A to page B, or
    between the postbacks for the same page? If from page A to page B, do you
    want to pass object on client side or on server side? If on server side,
    hidden fields won't help you.

    Eliyahu

    "Mark" <> wrote in message
    news:eYYFe$...
    > Assume you have a web application with many different web pages, and you'd
    > like to avoid using cookies and storing session state in any form. Assume
    > further that bandwidth and security are not issues.
    >
    > Could you conceivably store a serialized object containing state
    > information in a hidden form field, and pass it from page to page to page
    > avoiding the use of cookies and session data?
    >
    > Thanks.
    >
    > Mark
    >
    >
    >
    Eliyahu Goldin, Feb 19, 2006
    #4
  5. Hi Mark,

    As other members have mentioned, you can use html hidden form fields to
    store some string data or serialized objects' content. However, for posting
    from page to page ...., this is difficult. Are you using ASP.NET 2.0? If
    so, it support cross page posting, however, this still require us to do
    POST between pages so that the html form fields can be passed from original
    page to target page.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], Feb 20, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark

    Using POST to preserve state

    Mark, Dec 13, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    415
    Andrew Robinson
    Dec 15, 2005
  2. zwieback89
    Replies:
    1
    Views:
    309
    Roland Hall
    Feb 2, 2007
  3. Grzegorz Chrupala
    Replies:
    2
    Views:
    190
    Grzegorz Chrupala
    Jun 30, 2003
  4. Replies:
    0
    Views:
    267
  5. Replies:
    5
    Views:
    165
Loading...

Share This Page