Object Persistence

G

Guest

I am trying to persist an instance specific object without using a session
object. Is this possible?

For example:
Class object: Car
Properties: Make, Model

Car.Make = Ford
Car.Model = F150

I would like to persist the object across postbacks without using a session
object. Or, if I do have to use a session object, what is the cleanest
mechinsim. Right now I save the object in the session after each property
change.
 
B

Ben Dewey

Try using ViewState:

[Category("Data")]
[DefaultValue("")]
[Bindable(true)]
public Car SelectedCar
{
get
{
object c = ViewState["SelectedCar"];
return (c == null) ? new Car(): (Car)c;
}
set
{
ViewState["SelectedCar"] = value;
}
}
 
C

Cowboy \(Gregory A. Beamer\)

If you are talking a single page, ViewState is an option for persistence.
You can also create static variables, but you will have to key them to the
user. This means you either stick them in session or create your own
"session" mechanism. There are also other built in ASP.NET cache mechanism
(a search for "cache" and "asp.net" should yeield at least one article).

I would not be as fearful of session in ASP.NET as we were in traditional
ASP. It is far less dangerous, esp. if you think things through and only
store objects that have session scope.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
 
G

Guest

Here are my views regarding your requirement

1. If the object is to be persisted across users think of Application objects
2. If the object is to be persisted across the pages for a user think of
session objects. If you are using ASP.NET 2.0 think of exploring Profile
Objects
3. If you want to persist the object across post back for a single page,
think of ViewState. ViewState has the limiation on amount of storage. If you
object is big ViewState might impact performance
4. If your object is big and you've performance consideration try DataCaching.
Data Caching persists user object on the IIS Memory. Data caching is similar
to Application objects. Data Caching cannot store too much of information.

Just analyze the above and figure out what's the best option for you....
 

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

Ask a Question

Top