|
-
Nov 5th, 2004, 02:03 AM
#1
Thread Starter
Hyperactive Member
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.
-
Nov 5th, 2004, 04:59 AM
#2
Fanatic Member
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.
-
Nov 5th, 2004, 05:18 AM
#3
Thread Starter
Hyperactive Member
how to use the server state session and as i wrote that session variabels some times become night mare .
are there any other soloutions..?
-
Nov 5th, 2004, 09:59 AM
#4
Fanatic Member
What kind of objects are we talking about ?
-
Nov 5th, 2004, 02:23 PM
#5
I wonder how many charact
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:
'for a viewstate object
Page.Viewstate.Add("FirstName","Fred")
'for a session object
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:
Page.Session.Add("FirstName,"Greg")
And you can test for existence of an item using
VB Code:
If Page.Session.Item("FirstName") Is Nothing Then
'was not assigned
And you can remove an item by using
VB Code:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|