Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > lifetime of Session object

Reply
Thread Tools

lifetime of Session object

 
 
Colin Basterfield
Guest
Posts: n/a
 
      06-01-2004
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




 
Reply With Quote
 
 
 
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      06-03-2004
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...b;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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>
>



 
Reply With Quote
 
 
 
 
Colin Basterfield
Guest
Posts: n/a
 
      06-03-2004
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 [MVP]" <vapor at steaming post office> wrote in message
news:(E-Mail Removed)...
> 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...b;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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
lifetime of Session and Application ??? Chris ASP .Net 1 06-04-2010 08:19 AM
Worker process and Cache object's lifetime =?Utf-8?B?RGlmZmlkZW50?= ASP .Net 1 02-02-2006 08:50 PM
asynchronous calls and object lifetime foldface@yahoo.co.uk ASP .Net 0 11-01-2005 09:19 AM
lifetime of temporary object from function return & optimization pt C++ 8 06-01-2005 01:11 AM
SWIG: Tie lifetime of object to a result Oliver Tengler Python 0 11-14-2003 08:12 AM



Advertisments