Using
SessionState
is the solution.
Let us assume that you have a
Car
object which some basic properties, along with a
CarDetail
object property, something like as follows:
public class Car
{
public string Make {get;set;}
public string Model {get;set;}
public CarDetail {get;set;}
}
The
CarDetail
class may have some detail properties as follows:
public class Car
{
public int Year {get;set;}
public Coler coler {get;set;}
}
And, the
CarDetail
may have another objects as it's property.
Let's call this an object graph, where the
Car
object contains other object (
CarDetail
) which may contain other object(s) as property.
So, what you have to do is, when your page is loaded first, you load all basic and detailed information for the requested
Car
from the database and populate the data in the
Car
object graph. Then, you store the
Car
object in the
Session
. For later page request, you serve the
Car
object data from the
Session
.
Here is a sample method that does this:
protected Car GetCar(int carId)
{
Car car = null;
if(Session["Car"] == null)
{
car = GetCar(carId);
Session["Car"] = car;
}
else
{
car = Session["Car"] as Car;
}
return car;
}
Hope, this helps