Results 1 to 3 of 3

Thread: Can I store an Object in ViewState?

  1. #1

    Thread Starter
    Lively Member tgoodmannz's Avatar
    Join Date
    Sep 2000
    Location
    Mid On at the Pavillion End
    Posts
    102

    Question Can I store an Object in ViewState?

    Sorry another newbie post here...

    Is it possible to store an Object against a page between form Posts?

    ViewState will only take a string .. are there any other .. ways of storing the object or do I need a typeconverter of some sort?

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Absolutely!

    All you have to do is to cast the object back when you need it:
    Code:
    ViewState["yourObject"] = yourObject;
    
    ...to read
    YourObjectType yourObject = (YourObjectType)ViewState["yourObject"];

  3. #3

    Thread Starter
    Lively Member tgoodmannz's Avatar
    Join Date
    Sep 2000
    Location
    Mid On at the Pavillion End
    Posts
    102
    Thanks Serge!

    Just for the record, the typecasting in VBScript is:

    Code:
            myObject = DirectCast(viewstate("myObject"), myObjectType)
    Unfortunately the object I'm handling is not Serializable - I think that is my next job ...

    Cheers,
    Tim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width