473,569 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

lifetime of Session object

Hi,

I am confused...

I have the following code in my Page_Load method
private void Page_Load(objec t sender, System.EventArg s e)

{

// Put user code to initialize the page here

if (!IsPostBack)

{

SiteSummary siteSummary = new SiteSummary();

RevenueList revList = siteSummary.Get RevenueList();

Session["RevenueLis t"] = 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)Se ssion["RevenueLis t"];

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 3443
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******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

I am confused...

I have the following code in my Page_Load method
private void Page_Load(objec t sender, System.EventArg s e)

{

// Put user code to initialize the page here

if (!IsPostBack)

{

SiteSummary siteSummary = new SiteSummary();

RevenueList revList = siteSummary.Get RevenueList();

Session["RevenueLis t"] = 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)Se ssion["RevenueLis t"];

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******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

I am confused...

I have the following code in my Page_Load method
private void Page_Load(objec t sender, System.EventArg s e)

{

// Put user code to initialize the page here

if (!IsPostBack)

{

SiteSummary siteSummary = new SiteSummary();

RevenueList revList = siteSummary.Get RevenueList();

Session["RevenueLis t"] = 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)Se ssion["RevenueLis t"];

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
1061
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. Page1.asp <%
14
3133
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 it makes difference to explicitly put them to null after working with them is done - it somehow makes the GC collect them sooner, like here: void...
14
4367
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 (1) ----------- #include <string> using std::string;
6
1686
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 it seems to keep working even after the initiating session is closed with session.abandon. Question... what will be the lifetime of this object...
0
1270
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 remote object in its constructor. When a client application starts it connects remote object, registers events and monitors service state. So far so...
2
1420
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 drop down combobox filled with a list of stuff, like employee names etc. I can select a persons name and see the codebehind event fired. No news flash...
3
1556
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
2673
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; } private:
5
1471
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"; } ~MyClass() { std::cout << "destructor\n"; }
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7678
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6286
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.