Results 1 to 5 of 5

Thread: Best way to persist Objcets values

  1. #1

    Thread Starter
    Hyperactive Member Kirun's Avatar
    Join Date
    Oct 2001
    Location
    Karachi , Pakistan
    Posts
    333

    Question Best way to persist Objcets values

    How can one persist teh data values over diffrent webpages.
    I have a collection objects ,and once the object is populated i want to perisist the object and want to use this object and its peroperties at varied times in diffrent webpages.
    I tried the session variabels ,but actually i dont know how to exactly use session variabels with objects and properties. I have read many times that these session variabels are night mare and you should use another ways to make data persistant.

  2. #2
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    It sounds to me that you need to use State Server Session state.

    No other form of session state will allow you to session complex objects.

    I'm not sure but you may be able to cache complex objects but I'm not sure.

    I'm sure cleverer people than myself will be able to comment on that one.

    Hope this helps.

    Parksie

  3. #3

    Thread Starter
    Hyperactive Member Kirun's Avatar
    Join Date
    Oct 2001
    Location
    Karachi , Pakistan
    Posts
    333

    Exclamation

    how to use the server state session and as i wrote that session variabels some times become night mare .

    are there any other soloutions..?

  4. #4
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    What kind of objects are we talking about ?

    Parksie

  5. #5
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    The only reason people call it a nightmare is because they usually define a class, make a collection class for it, and then try saving it in session or view state.

    The basic trick is to be sure your objects are serializable. Primitive types such as strings and integers and certain classes are already marked for serialization (datasets for example).

    As an example case for viewstate, the object has to be serializable to some sort of text string (datasets for example can be written as xml, and xml can be stored in a string).

    Viewstate and session state take key/value pairs. You assign a key (name) and a value. The name is used to recall the object later, or remove the object by passing its name. Keys are CASE-SENSITIVE.

    To add an object like FirstName with a value of 'Fred'.
    VB Code:
    1. 'for a viewstate object
    2. Page.Viewstate.Add("FirstName","Fred")
    3. 'for a session object
    4. Page.Session.Add("FirstName,"Fred")

    You can overwrite an existing value simply by calling the Add method again with with its new value.
    VB Code:
    1. Page.Session.Add("FirstName,"Greg")

    And you can test for existence of an item using
    VB Code:
    1. If Page.Session.Item("FirstName") Is Nothing Then
    2. 'was not assigned

    And you can remove an item by using
    VB Code:
    1. Page.Session.Remove("FirstName")

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