lifetime of Session object

  • Thread starter Colin Basterfield
  • Start date
C

Colin Basterfield

Hi,

I am confused...

I have the following code in my Page_Load method
private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

if (!IsPostBack)

{

SiteSummary siteSummary = new SiteSummary();

RevenueList revList = siteSummary.GetRevenueList();

Session["RevenueList"] = revList;

BindGrid();

}

}

Now my understanding is that I could , and have been loading the Revenue
list directly into the Session object, and then in the BindGrid() method I
assign the collection to the datalist datasource thus:

private void BindGrid()

{

dlRevenueItems.DataSource = (RevenueList)Session["RevenueList"];

dlRevenueItems.DataBind();

}

Now this was working yesterday, but now all of a sudden, when I run it the
assignment to the datasource fails, saying that it isn't set to the instance
of an object.

I am wholly confused when something works intermittently when there has been
no code change.

I can't declare the list private to the overall page class as it falls out
of scope the minute the BindGrid is called, hence the change to the Session
object.

Confused, probably out of ignorance

TIA

Colin B
 
A

Alvin Bruney [MVP]

well, you are chancing by binding directly out of session since the runtime
makes no guarantee that the objects in session will be around when you use
it. I believe your real question is why is the data not there?
You need to examine the session id before you go any further. put some code
to display the session.id on each page load. if the session id changes, your
session variables will no longer be present since the session end event
would have been triggered.

here is some background:
http://support.microsoft.com/default.aspx?scid=kb;en-us;555082
 
C

Colin Basterfield

Hi there,

many thanks for this, I will do some checking, both in the code and the
link, however I did do some checks by breaking at the point where it tries
to load the RevList from the Session object, and using a quick watch I could
see that the data was in fact there, but when I stepped it on from that
point, that is when it goes boom!

Anyways thanks again.
Colin

Alvin Bruney said:
well, you are chancing by binding directly out of session since the runtime
makes no guarantee that the objects in session will be around when you use
it. I believe your real question is why is the data not there?
You need to examine the session id before you go any further. put some code
to display the session.id on each page load. if the session id changes, your
session variables will no longer be present since the session end event
would have been triggered.

here is some background:
http://support.microsoft.com/default.aspx?scid=kb;en-us;555082
--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Colin Basterfield said:
Hi,

I am confused...

I have the following code in my Page_Load method
private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

if (!IsPostBack)

{

SiteSummary siteSummary = new SiteSummary();

RevenueList revList = siteSummary.GetRevenueList();

Session["RevenueList"] = revList;

BindGrid();

}

}

Now my understanding is that I could , and have been loading the Revenue
list directly into the Session object, and then in the BindGrid() method I
assign the collection to the datalist datasource thus:

private void BindGrid()

{

dlRevenueItems.DataSource = (RevenueList)Session["RevenueList"];

dlRevenueItems.DataBind();

}

Now this was working yesterday, but now all of a sudden, when I run it the
assignment to the datasource fails, saying that it isn't set to the
instance
of an object.

I am wholly confused when something works intermittently when there has
been
no code change.

I can't declare the list private to the overall page class as it falls out
of scope the minute the BindGrid is called, hence the change to the
Session
object.

Confused, probably out of ignorance

TIA

Colin B
 

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

Similar Threads

Lifetime of static member variable in ASP.NET 3
sorting gridview question 6
Button_Click and Session 8
How to Page a DataGrid 0
Session Problems 2
session 1
lifetime of temp string object 15
Session not working 4

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top