473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

lifetime of Session object

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


Nov 18 '05 #1
2 3435
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" <co**************@hotmail.com> wrote in message
news:O7**************@TK2MSFTNGP11.phx.gbl...
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

Nov 18 '05 #2
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:u2**************@TK2MSFTNGP09.phx.gbl...
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" <co**************@hotmail.com> wrote in message
news:O7**************@TK2MSFTNGP11.phx.gbl...
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


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Elie Grouchko | last post by:
Hi All I am on page page1.asp and I have a reference to an ASP Vbscript object. I need to use Server.Execute("page2.asp") and want to pass a reference to this object using a session variable....
14
by: MuZZy | last post by:
Hi, Lately i've been (and still am) fixing some memory leaks problems in the project i just took over when i got this new job. Among the other issues i've noticed that for localy created objects...
14
by: Frederick Gotham | last post by:
There is a common misconception, (one which I myself also held at one point), that a const reference can "extend the lifetime of a temporary". Examples such as the following are given: Snippet...
6
by: fantum | last post by:
I have created a small activex dll to do a background task on my web server. I fire it off with a set myjob = server.createobject(myactivex) and it runs. I do not do a set myjob = nothing and so...
0
by: Kürşat | last post by:
Hi all, I want to host a remote object in a windows service. This remote object fires events about service state. Clients connect and consume this events. The service configures and marshal...
2
by: Control Freq | last post by:
Hi, I am still new to dotnet programming, and ASP.NET in general. Something that has been bugging me for a while is this: In a Web Form application, using C# in the codebehind. If I have a...
3
by: mario semo | last post by:
Hello, What does the C++ Norm says about the lifetime of compiler generated temporary variables? #include <stdio.h> class BaseRef {...
6
by: better_cs_now | last post by:
Hello all, class Foo {/* Details don't matter */}; class Bar { public: Bar(): m_Foo(/* Construct a Foo however it wants to be constructed */); const Foo &GetFoo() const { return m_Foo; }...
5
by: Juha Nieminen | last post by:
Let's assume we have a class like this: //--------------------------------------------------------- #include <iostream> class MyClass { public: MyClass() { std::cout << "constructor\n"; }...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.