p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

aspx thread: Page_Unload will not execute


Message #1 by "Jeffrey Tournier" <jeffrey.tournier@v...> on Mon, 8 Jul 2002 14:32:17
Dear you,

I'am creating an ASP page which contains data in a dataset. This dataset 
is connected to a couple of textboxes. I want to be able to edit het data 
in the textboxes and when I leave the page I want to use the Page_Unload 
to save my data to the dataset. 

This dataset will be kept in the Session so I can use it on the next pages.

I'am using VB as programming language.

Here is the Page_Unload I'm using:
Private Sub Page_Unload(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles MyBase.Unload
        writeData()
End Sub

Can anyone help me with this?
I read an article from september 2001 where a solution for C# was provided 
but this did not work. I don't know if it worked for Eirik then!

Regards,
Jeffrey
Message #2 by Feduke Cntr Charles R <FedukeCR@m...> on Mon, 8 Jul 2002 09:35:22 -0400
Jeffrey,

	Do you mean like when you close the browser you expect Page_Unload
to fire?  If so, its not going to happen.  Once a page is served to a
client, that's it - end of story.  The server doesn't get a response from
the client on any other action, whether its to close the browser, reboot the
machine, go to another site - nothing.  Your Page_Unload actually fires when
ASP.NET has finished all of its other actions with the page (like load
postback data, load viewstate, load, render, etc).  You can use the
Page_Unload to do things like clean up or reset various objects you need for
other pages, but don't use it to save data.  Instead, consider making a save
button on the page that when clicked fires an event that calls your
writeData.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:32 AM
To: ASP+
Subject: [aspx] Page_Unload will not execute


Dear you,

I'am creating an ASP page which contains data in a dataset. This dataset 
is connected to a couple of textboxes. I want to be able to edit het data 
in the textboxes and when I leave the page I want to use the Page_Unload 
to save my data to the dataset. 

This dataset will be kept in the Session so I can use it on the next pages.

I'am using VB as programming language.

Here is the Page_Unload I'm using:
Private Sub Page_Unload(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles MyBase.Unload
        writeData()
End Sub

Can anyone help me with this?
I read an article from september 2001 where a solution for C# was provided 
but this did not work. I don't know if it worked for Eirik then!

Regards,
Jeffrey
Message #3 by "Jeffrey Tournier" <jeffrey.tournier@v...> on Mon, 8 Jul 2002 14:56:36
Chuck,

Thanks for your reply. Reading your answer I thought by myself that I 
could have thougth of this myself.
It was suppost to happen on a Hyperlink. Another option was to create an 
Event there I would be able to use the Write. But then the problem occures 
that the links are created dynamically and the event will not trigger. 

I read a lot of articles about this but was unable to find a working 
answer. All samples returned start whit the generation of the controls in 
the Page load. In my code this is not the case. As long as the controls 
are not created again the event will not trigger.

Hope to find a good solution, till that time I will add the less nice 
option of an button to save.

Regards,
Jeffrey


> Jeffrey,

	Do you mean like when you close the browser you expect Page_Unload
to fire?  If so, its not going to happen.  Once a page is served to a
client, that's it - end of story.  The server doesn't get a response from
the client on any other action, whether its to close the browser, reboot 
the
machine, go to another site - nothing.  Your Page_Unload actually fires 
when
ASP.NET has finished all of its other actions with the page (like load
postback data, load viewstate, load, render, etc).  You can use the
Page_Unload to do things like clean up or reset various objects you need 
for
other pages, but don't use it to save data.  Instead, consider making a 
save
button on the page that when clicked fires an event that calls your
writeData.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:32 AM
To: ASP+
Subject: [aspx] Page_Unload will not execute


Dear you,

I'am creating an ASP page which contains data in a dataset. This dataset 
is connected to a couple of textboxes. I want to be able to edit het data 
in the textboxes and when I leave the page I want to use the Page_Unload 
to save my data to the dataset. 

This dataset will be kept in the Session so I can use it on the next pages.

I'am using VB as programming language.

Here is the Page_Unload I'm using:
Private Sub Page_Unload(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles MyBase.Unload
        writeData()
End Sub

Can anyone help me with this?
I read an article from september 2001 where a solution for C# was provided 
but this did not work. I don't know if it worked for Eirik then!

Regards,
Jeffrey
Message #4 by Feduke Cntr Charles R <FedukeCR@m...> on Mon, 8 Jul 2002 09:58:57 -0400
Jeffrey,

	You want to make a hyperlink that fires the event?  You could always
use an <asp:LinkButton>, and if there's ever a time you don't want the
control to display in the user's browser, just Visible = false it.  I've
tried going the route of dynamically creating controls and associating
events to them, and it is not a friendly road to travel.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:57 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Chuck,

Thanks for your reply. Reading your answer I thought by myself that I 
could have thougth of this myself.
It was suppost to happen on a Hyperlink. Another option was to create an 
Event there I would be able to use the Write. But then the problem occures 
that the links are created dynamically and the event will not trigger. 

I read a lot of articles about this but was unable to find a working 
answer. All samples returned start whit the generation of the controls in 
the Page load. In my code this is not the case. As long as the controls 
are not created again the event will not trigger.

Hope to find a good solution, till that time I will add the less nice 
option of an button to save.

Regards,
Jeffrey


> Jeffrey,

	Do you mean like when you close the browser you expect Page_Unload
to fire?  If so, its not going to happen.  Once a page is served to a
client, that's it - end of story.  The server doesn't get a response from
the client on any other action, whether its to close the browser, reboot 
the
machine, go to another site - nothing.  Your Page_Unload actually fires 
when
ASP.NET has finished all of its other actions with the page (like load
postback data, load viewstate, load, render, etc).  You can use the
Page_Unload to do things like clean up or reset various objects you need 
for
other pages, but don't use it to save data.  Instead, consider making a 
save
button on the page that when clicked fires an event that calls your
writeData.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:32 AM
To: ASP+
Subject: [aspx] Page_Unload will not execute


Dear you,

I'am creating an ASP page which contains data in a dataset. This dataset 
is connected to a couple of textboxes. I want to be able to edit het data 
in the textboxes and when I leave the page I want to use the Page_Unload 
to save my data to the dataset. 

This dataset will be kept in the Session so I can use it on the next pages.

I'am using VB as programming language.

Here is the Page_Unload I'm using:
Private Sub Page_Unload(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles MyBase.Unload
        writeData()
End Sub

Can anyone help me with this?
I read an article from september 2001 where a solution for C# was provided 
but this did not work. I don't know if it worked for Eirik then!

Regards,
Jeffrey
Message #5 by "Jeffrey Tournier" <Jeffrey.tournier@v...> on Mon, 8 Jul 2002 15:28:24
Chuck,

For some of our linkbuttons we are already using this, but the 
buttons/links I am talking about in this specific sample are generated for 
a project tool. I will try to explane in a few words:

We are creating a tool where our employees are able to enter there hours 
thru the internet. Each employee is working on several projects containing 
several activities. Because not all the employees are allowed to book 
hours on the same activities and not all activities are always available 
we created an asp:table which we dynamicaly fill with the available data.

The links we want to make now are the "Add Activity" links which will go 
to another page passing the projectID. So the user is able to enter a new 
Activity to his sheet and the press the return button to go back to his 
grid to enter his hours.

Because we do not know how many projects (and which projectID connected) 
there are we are not able to create them in advance and hide them 
afterwards. This technique we are using for overtime and compensation 
because we know for sure these options always exist but are not always 
necessary to show.

Regards,
Jeffrey

P.S. If you want I can send you a part of my code as it is rigth now but I 
cannot send you the database.

> Jeffrey,

	You want to make a hyperlink that fires the event?  You could 
always
use an <asp:LinkButton>, and if there's ever a time you don't want the
control to display in the user's browser, just Visible = false it.  I've
tried going the route of dynamically creating controls and associating
events to them, and it is not a friendly road to travel.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:57 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Chuck,

Thanks for your reply. Reading your answer I thought by myself that I 
could have thougth of this myself.
It was suppost to happen on a Hyperlink. Another option was to create an 
Event there I would be able to use the Write. But then the problem occures 
that the links are created dynamically and the event will not trigger. 

I read a lot of articles about this but was unable to find a working 
answer. All samples returned start whit the generation of the controls in 
the Page load. In my code this is not the case. As long as the controls 
are not created again the event will not trigger.

Hope to find a good solution, till that time I will add the less nice 
option of an button to save.

Regards,
Jeffrey


> Jeffrey,

	Do you mean like when you close the browser you expect Page_Unload
to fire?  If so, its not going to happen.  Once a page is served to a
client, that's it - end of story.  The server doesn't get a response from
the client on any other action, whether its to close the browser, reboot 
the
machine, go to another site - nothing.  Your Page_Unload actually fires 
when
ASP.NET has finished all of its other actions with the page (like load
postback data, load viewstate, load, render, etc).  You can use the
Page_Unload to do things like clean up or reset various objects you need 
for
other pages, but don't use it to save data.  Instead, consider making a 
save
button on the page that when clicked fires an event that calls your
writeData.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:32 AM
To: ASP+
Subject: [aspx] Page_Unload will not execute


Dear you,

I'am creating an ASP page which contains data in a dataset. This dataset 
is connected to a couple of textboxes. I want to be able to edit het data 
in the textboxes and when I leave the page I want to use the Page_Unload 
to save my data to the dataset. 

This dataset will be kept in the Session so I can use it on the next pages.

I'am using VB as programming language.

Here is the Page_Unload I'm using:
Private Sub Page_Unload(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles MyBase.Unload
        writeData()
End Sub

Can anyone help me with this?
I read an article from september 2001 where a solution for C# was provided 
but this did not work. I don't know if it worked for Eirik then!

Regards,
Jeffrey
Message #6 by Feduke Cntr Charles R <FedukeCR@m...> on Mon, 8 Jul 2002 10:52:13 -0400
Jeffrey,

	Okay, I know what you're trying to do.  I tried to do the same thing
myself by creating controls that had multiple controls like LinkButtons and
DropDownLists in *.cs files.  The controls must be alive and well before the
OnInit completes in order to receive an event, and they must have any events
associated with them already set by this time.  This still doesn't solve
your problem because you are getting your number of controls requirement
from the form's posted data, which is retrieved during the load post data.
You may be able to:

this.RegisterRequiresRaiseEvent(yourDynamicControl);

	A crap solution would be to initialize your maximum number of
controls possible, but hide them all.  Or, if you control the rate at which
the user can add items, then initialize the Session["count"] + 1 number of
controls in OnInit and register them all for post back events.  There is a
better way to do this, but I don't remember the steps exactly and the book I
read it from is sitting (useless) at home.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:Jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 11:28 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Chuck,

For some of our linkbuttons we are already using this, but the 
buttons/links I am talking about in this specific sample are generated for 
a project tool. I will try to explane in a few words:

We are creating a tool where our employees are able to enter there hours 
thru the internet. Each employee is working on several projects containing 
several activities. Because not all the employees are allowed to book 
hours on the same activities and not all activities are always available 
we created an asp:table which we dynamicaly fill with the available data.

The links we want to make now are the "Add Activity" links which will go 
to another page passing the projectID. So the user is able to enter a new 
Activity to his sheet and the press the return button to go back to his 
grid to enter his hours.

Because we do not know how many projects (and which projectID connected) 
there are we are not able to create them in advance and hide them 
afterwards. This technique we are using for overtime and compensation 
because we know for sure these options always exist but are not always 
necessary to show.

Regards,
Jeffrey

P.S. If you want I can send you a part of my code as it is rigth now but I 
cannot send you the database.

> Jeffrey,

	You want to make a hyperlink that fires the event?  You could 
always
use an <asp:LinkButton>, and if there's ever a time you don't want the
control to display in the user's browser, just Visible = false it.  I've
tried going the route of dynamically creating controls and associating
events to them, and it is not a friendly road to travel.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:57 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Chuck,

Thanks for your reply. Reading your answer I thought by myself that I 
could have thougth of this myself.
It was suppost to happen on a Hyperlink. Another option was to create an 
Event there I would be able to use the Write. But then the problem occures 
that the links are created dynamically and the event will not trigger. 

I read a lot of articles about this but was unable to find a working 
answer. All samples returned start whit the generation of the controls in 
the Page load. In my code this is not the case. As long as the controls 
are not created again the event will not trigger.

Hope to find a good solution, till that time I will add the less nice 
option of an button to save.

Regards,
Jeffrey


> Jeffrey,

	Do you mean like when you close the browser you expect Page_Unload
to fire?  If so, its not going to happen.  Once a page is served to a
client, that's it - end of story.  The server doesn't get a response from
the client on any other action, whether its to close the browser, reboot 
the
machine, go to another site - nothing.  Your Page_Unload actually fires 
when
ASP.NET has finished all of its other actions with the page (like load
postback data, load viewstate, load, render, etc).  You can use the
Page_Unload to do things like clean up or reset various objects you need 
for
other pages, but don't use it to save data.  Instead, consider making a 
save
button on the page that when clicked fires an event that calls your
writeData.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:32 AM
To: ASP+
Subject: [aspx] Page_Unload will not execute


Dear you,

I'am creating an ASP page which contains data in a dataset. This dataset 
is connected to a couple of textboxes. I want to be able to edit het data 
in the textboxes and when I leave the page I want to use the Page_Unload 
to save my data to the dataset. 

This dataset will be kept in the Session so I can use it on the next pages.

I'am using VB as programming language.

Here is the Page_Unload I'm using:
Private Sub Page_Unload(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles MyBase.Unload
        writeData()
End Sub

Can anyone help me with this?
I read an article from september 2001 where a solution for C# was provided 
but this did not work. I don't know if it worked for Eirik then!

Regards,
Jeffrey
Message #7 by "Chadrick" <chadm@d...> on Mon, 8 Jul 2002 10:55:58 -0400
Thanks for posting that Chuck - I'm interested in this thread too and
want to see how it pans out.

-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...] 
Sent: Monday, July 08, 2002 10:52 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute

Jeffrey,

	Okay, I know what you're trying to do.  I tried to do the same
thing
myself by creating controls that had multiple controls like LinkButtons
and
DropDownLists in *.cs files.  The controls must be alive and well before
the
OnInit completes in order to receive an event, and they must have any
events
associated with them already set by this time.  This still doesn't solve
your problem because you are getting your number of controls requirement
from the form's posted data, which is retrieved during the load post
data.
You may be able to:

this.RegisterRequiresRaiseEvent(yourDynamicControl);

	A crap solution would be to initialize your maximum number of
controls possible, but hide them all.  Or, if you control the rate at
which
the user can add items, then initialize the Session["count"] + 1 number
of
controls in OnInit and register them all for post back events.  There is
a
better way to do this, but I don't remember the steps exactly and the
book I
read it from is sitting (useless) at home.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:Jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 11:28 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Chuck,

For some of our linkbuttons we are already using this, but the 
buttons/links I am talking about in this specific sample are generated
for 
a project tool. I will try to explane in a few words:

We are creating a tool where our employees are able to enter there hours

thru the internet. Each employee is working on several projects
containing 
several activities. Because not all the employees are allowed to book 
hours on the same activities and not all activities are always available

we created an asp:table which we dynamicaly fill with the available
data.

The links we want to make now are the "Add Activity" links which will go

to another page passing the projectID. So the user is able to enter a
new 
Activity to his sheet and the press the return button to go back to his 
grid to enter his hours.

Because we do not know how many projects (and which projectID connected)

there are we are not able to create them in advance and hide them 
afterwards. This technique we are using for overtime and compensation 
because we know for sure these options always exist but are not always 
necessary to show.

Regards,
Jeffrey

P.S. If you want I can send you a part of my code as it is rigth now but
I 
cannot send you the database.

> Jeffrey,

	You want to make a hyperlink that fires the event?  You could 
always
use an <asp:LinkButton>, and if there's ever a time you don't want the
control to display in the user's browser, just Visible = false it.  I've
tried going the route of dynamically creating controls and associating
events to them, and it is not a friendly road to travel.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:57 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Chuck,

Thanks for your reply. Reading your answer I thought by myself that I 
could have thougth of this myself.
It was suppost to happen on a Hyperlink. Another option was to create an

Event there I would be able to use the Write. But then the problem
occures 
that the links are created dynamically and the event will not trigger. 

I read a lot of articles about this but was unable to find a working 
answer. All samples returned start whit the generation of the controls
in 
the Page load. In my code this is not the case. As long as the controls 
are not created again the event will not trigger.

Hope to find a good solution, till that time I will add the less nice 
option of an button to save.

Regards,
Jeffrey


> Jeffrey,

	Do you mean like when you close the browser you expect
Page_Unload
to fire?  If so, its not going to happen.  Once a page is served to a
client, that's it - end of story.  The server doesn't get a response
from
the client on any other action, whether its to close the browser, reboot

the
machine, go to another site - nothing.  Your Page_Unload actually fires 
when
ASP.NET has finished all of its other actions with the page (like load
postback data, load viewstate, load, render, etc).  You can use the
Page_Unload to do things like clean up or reset various objects you need

for
other pages, but don't use it to save data.  Instead, consider making a 
save
button on the page that when clicked fires an event that calls your
writeData.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:32 AM
To: ASP+
Subject: [aspx] Page_Unload will not execute


Dear you,

I'am creating an ASP page which contains data in a dataset. This dataset

is connected to a couple of textboxes. I want to be able to edit het
data 
in the textboxes and when I leave the page I want to use the Page_Unload

to save my data to the dataset. 

This dataset will be kept in the Session so I can use it on the next
pages.

I'am using VB as programming language.

Here is the Page_Unload I'm using:
Private Sub Page_Unload(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles MyBase.Unload
        writeData()
End Sub

Can anyone help me with this?
I read an article from september 2001 where a solution for C# was
provided 
but this did not work. I don't know if it worked for Eirik then!

Regards,
Jeffrey




Message #8 by Feduke Cntr Charles R <FedukeCR@m...> on Mon, 8 Jul 2002 11:39:49 -0400
> Thanks for posting that Chuck - I'm interested in this thread too and
> want to see how it pans out.

	I'll bring the book in tomorrow and relate the information if its
correct.

- Chuck

-----Original Message-----
From: Chadrick [mailto:chadm@d...]
Sent: Monday, July 08, 2002 10:56 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Thanks for posting that Chuck - I'm interested in this thread too and
want to see how it pans out.

-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...] 
Sent: Monday, July 08, 2002 10:52 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute

Jeffrey,

	Okay, I know what you're trying to do.  I tried to do the same
thing
myself by creating controls that had multiple controls like LinkButtons
and
DropDownLists in *.cs files.  The controls must be alive and well before
the
OnInit completes in order to receive an event, and they must have any
events
associated with them already set by this time.  This still doesn't solve
your problem because you are getting your number of controls requirement
from the form's posted data, which is retrieved during the load post
data.
You may be able to:

this.RegisterRequiresRaiseEvent(yourDynamicControl);

	A crap solution would be to initialize your maximum number of
controls possible, but hide them all.  Or, if you control the rate at
which
the user can add items, then initialize the Session["count"] + 1 number
of
controls in OnInit and register them all for post back events.  There is
a
better way to do this, but I don't remember the steps exactly and the
book I
read it from is sitting (useless) at home.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:Jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 11:28 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Chuck,

For some of our linkbuttons we are already using this, but the 
buttons/links I am talking about in this specific sample are generated
for 
a project tool. I will try to explane in a few words:

We are creating a tool where our employees are able to enter there hours

thru the internet. Each employee is working on several projects
containing 
several activities. Because not all the employees are allowed to book 
hours on the same activities and not all activities are always available

we created an asp:table which we dynamicaly fill with the available
data.

The links we want to make now are the "Add Activity" links which will go

to another page passing the projectID. So the user is able to enter a
new 
Activity to his sheet and the press the return button to go back to his 
grid to enter his hours.

Because we do not know how many projects (and which projectID connected)

there are we are not able to create them in advance and hide them 
afterwards. This technique we are using for overtime and compensation 
because we know for sure these options always exist but are not always 
necessary to show.

Regards,
Jeffrey

P.S. If you want I can send you a part of my code as it is rigth now but
I 
cannot send you the database.

> Jeffrey,

	You want to make a hyperlink that fires the event?  You could 
always
use an <asp:LinkButton>, and if there's ever a time you don't want the
control to display in the user's browser, just Visible = false it.  I've
tried going the route of dynamically creating controls and associating
events to them, and it is not a friendly road to travel.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:57 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Chuck,

Thanks for your reply. Reading your answer I thought by myself that I 
could have thougth of this myself.
It was suppost to happen on a Hyperlink. Another option was to create an

Event there I would be able to use the Write. But then the problem
occures 
that the links are created dynamically and the event will not trigger. 

I read a lot of articles about this but was unable to find a working 
answer. All samples returned start whit the generation of the controls
in 
the Page load. In my code this is not the case. As long as the controls 
are not created again the event will not trigger.

Hope to find a good solution, till that time I will add the less nice 
option of an button to save.

Regards,
Jeffrey


> Jeffrey,

	Do you mean like when you close the browser you expect
Page_Unload
to fire?  If so, its not going to happen.  Once a page is served to a
client, that's it - end of story.  The server doesn't get a response
from
the client on any other action, whether its to close the browser, reboot

the
machine, go to another site - nothing.  Your Page_Unload actually fires 
when
ASP.NET has finished all of its other actions with the page (like load
postback data, load viewstate, load, render, etc).  You can use the
Page_Unload to do things like clean up or reset various objects you need

for
other pages, but don't use it to save data.  Instead, consider making a 
save
button on the page that when clicked fires an event that calls your
writeData.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:32 AM
To: ASP+
Subject: [aspx] Page_Unload will not execute


Dear you,

I'am creating an ASP page which contains data in a dataset. This dataset

is connected to a couple of textboxes. I want to be able to edit het
data 
in the textboxes and when I leave the page I want to use the Page_Unload

to save my data to the dataset. 

This dataset will be kept in the Session so I can use it on the next
pages.

I'am using VB as programming language.

Here is the Page_Unload I'm using:
Private Sub Page_Unload(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles MyBase.Unload
        writeData()
End Sub

Can anyone help me with this?
I read an article from september 2001 where a solution for C# was
provided 
but this did not work. I don't know if it worked for Eirik then!

Regards,
Jeffrey





Message #9 by "Subraya Hegde" <subrayah@i...> on Tue, 9 Jul 2002 11:20:26 +0530
Hi Jeffery,

    I also am very much interested in this thread. I appreciate if you could
explain
your requirements once again in detail and send some sample code. Cos I
worked
on a similar kind of application using classic ASP.

Best Regards,
HegdeS.

Message #10 by "Jeffrey Tournier" <jeffrey.tournier@v...> on Tue, 16 Jul 2002 08:12:17
Chuck,

Did you already get a chance to bring the book?

Regards,
Jeffrey

> > Thanks for posting that Chuck - I'm interested in this thread too and
> want to see how it pans out.

	I'll bring the book in tomorrow and relate the information if its
correct.

- Chuck

-----Original Message-----
From: Chadrick [mailto:chadm@d...]
Sent: Monday, July 08, 2002 10:56 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Thanks for posting that Chuck - I'm interested in this thread too and
want to see how it pans out.

-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...] 
Sent: Monday, July 08, 2002 10:52 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute

Jeffrey,

	Okay, I know what you're trying to do.  I tried to do the same
thing
myself by creating controls that had multiple controls like LinkButtons
and
DropDownLists in *.cs files.  The controls must be alive and well before
the
OnInit completes in order to receive an event, and they must have any
events
associated with them already set by this time.  This still doesn't solve
your problem because you are getting your number of controls requirement
from the form's posted data, which is retrieved during the load post
data.
You may be able to:

this.RegisterRequiresRaiseEvent(yourDynamicControl);

	A crap solution would be to initialize your maximum number of
controls possible, but hide them all.  Or, if you control the rate at
which
the user can add items, then initialize the Session["count"] + 1 number
of
controls in OnInit and register them all for post back events.  There is
a
better way to do this, but I don't remember the steps exactly and the
book I
read it from is sitting (useless) at home.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:Jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 11:28 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Chuck,

For some of our linkbuttons we are already using this, but the 
buttons/links I am talking about in this specific sample are generated
for 
a project tool. I will try to explane in a few words:

We are creating a tool where our employees are able to enter there hours

thru the internet. Each employee is working on several projects
containing 
several activities. Because not all the employees are allowed to book 
hours on the same activities and not all activities are always available

we created an asp:table which we dynamicaly fill with the available
data.

The links we want to make now are the "Add Activity" links which will go

to another page passing the projectID. So the user is able to enter a
new 
Activity to his sheet and the press the return button to go back to his 
grid to enter his hours.

Because we do not know how many projects (and which projectID connected)

there are we are not able to create them in advance and hide them 
afterwards. This technique we are using for overtime and compensation 
because we know for sure these options always exist but are not always 
necessary to show.

Regards,
Jeffrey

P.S. If you want I can send you a part of my code as it is rigth now but
I 
cannot send you the database.

> Jeffrey,

	You want to make a hyperlink that fires the event?  You could 
always
use an <asp:LinkButton>, and if there's ever a time you don't want the
control to display in the user's browser, just Visible = false it.  I've
tried going the route of dynamically creating controls and associating
events to them, and it is not a friendly road to travel.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:57 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Chuck,

Thanks for your reply. Reading your answer I thought by myself that I 
could have thougth of this myself.
It was suppost to happen on a Hyperlink. Another option was to create an

Event there I would be able to use the Write. But then the problem
occures 
that the links are created dynamically and the event will not trigger. 

I read a lot of articles about this but was unable to find a working 
answer. All samples returned start whit the generation of the controls
in 
the Page load. In my code this is not the case. As long as the controls 
are not created again the event will not trigger.

Hope to find a good solution, till that time I will add the less nice 
option of an button to save.

Regards,
Jeffrey


> Jeffrey,

	Do you mean like when you close the browser you expect
Page_Unload
to fire?  If so, its not going to happen.  Once a page is served to a
client, that's it - end of story.  The server doesn't get a response
from
the client on any other action, whether its to close the browser, reboot

the
machine, go to another site - nothing.  Your Page_Unload actually fires 
when
ASP.NET has finished all of its other actions with the page (like load
postback data, load viewstate, load, render, etc).  You can use the
Page_Unload to do things like clean up or reset various objects you need

for
other pages, but don't use it to save data.  Instead, consider making a 
save
button on the page that when clicked fires an event that calls your
writeData.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:32 AM
To: ASP+
Subject: [aspx] Page_Unload will not execute


Dear you,

I'am creating an ASP page which contains data in a dataset. This dataset

is connected to a couple of textboxes. I want to be able to edit het
data 
in the textboxes and when I leave the page I want to use the Page_Unload

to save my data to the dataset. 

This dataset will be kept in the Session so I can use it on the next
pages.

I'am using VB as programming language.

Here is the Page_Unload I'm using:
Private Sub Page_Unload(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles MyBase.Unload
        writeData()
End Sub

Can anyone help me with this?
I read an article from september 2001 where a solution for C# was
provided 
but this did not work. I don't know if it worked for Eirik then!

Regards,
Jeffrey





Message #11 by Feduke Cntr Charles R <FedukeCR@m...> on Tue, 16 Jul 2002 09:26:58 -0400
Oh yeah, it is long after "tomorrow" now.  I've CC'd my home address on this
so I can do it tonight.

Sorry for the delay!

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Tuesday, July 16, 2002 4:12 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Chuck,

Did you already get a chance to bring the book?

Regards,
Jeffrey

> > Thanks for posting that Chuck - I'm interested in this thread too and
> want to see how it pans out.

	I'll bring the book in tomorrow and relate the information if its
correct.

- Chuck

-----Original Message-----
From: Chadrick [mailto:chadm@d...]
Sent: Monday, July 08, 2002 10:56 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Thanks for posting that Chuck - I'm interested in this thread too and
want to see how it pans out.

-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...] 
Sent: Monday, July 08, 2002 10:52 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute

Jeffrey,

	Okay, I know what you're trying to do.  I tried to do the same
thing
myself by creating controls that had multiple controls like LinkButtons
and
DropDownLists in *.cs files.  The controls must be alive and well before
the
OnInit completes in order to receive an event, and they must have any
events
associated with them already set by this time.  This still doesn't solve
your problem because you are getting your number of controls requirement
from the form's posted data, which is retrieved during the load post
data.
You may be able to:

this.RegisterRequiresRaiseEvent(yourDynamicControl);

	A crap solution would be to initialize your maximum number of
controls possible, but hide them all.  Or, if you control the rate at
which
the user can add items, then initialize the Session["count"] + 1 number
of
controls in OnInit and register them all for post back events.  There is
a
better way to do this, but I don't remember the steps exactly and the
book I
read it from is sitting (useless) at home.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:Jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 11:28 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Chuck,

For some of our linkbuttons we are already using this, but the 
buttons/links I am talking about in this specific sample are generated
for 
a project tool. I will try to explane in a few words:

We are creating a tool where our employees are able to enter there hours

thru the internet. Each employee is working on several projects
containing 
several activities. Because not all the employees are allowed to book 
hours on the same activities and not all activities are always available

we created an asp:table which we dynamicaly fill with the available
data.

The links we want to make now are the "Add Activity" links which will go

to another page passing the projectID. So the user is able to enter a
new 
Activity to his sheet and the press the return button to go back to his 
grid to enter his hours.

Because we do not know how many projects (and which projectID connected)

there are we are not able to create them in advance and hide them 
afterwards. This technique we are using for overtime and compensation 
because we know for sure these options always exist but are not always 
necessary to show.

Regards,
Jeffrey

P.S. If you want I can send you a part of my code as it is rigth now but
I 
cannot send you the database.

> Jeffrey,

	You want to make a hyperlink that fires the event?  You could 
always
use an <asp:LinkButton>, and if there's ever a time you don't want the
control to display in the user's browser, just Visible = false it.  I've
tried going the route of dynamically creating controls and associating
events to them, and it is not a friendly road to travel.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:57 AM
To: ASP+
Subject: [aspx] RE: Page_Unload will not execute


Chuck,

Thanks for your reply. Reading your answer I thought by myself that I 
could have thougth of this myself.
It was suppost to happen on a Hyperlink. Another option was to create an

Event there I would be able to use the Write. But then the problem
occures 
that the links are created dynamically and the event will not trigger. 

I read a lot of articles about this but was unable to find a working 
answer. All samples returned start whit the generation of the controls
in 
the Page load. In my code this is not the case. As long as the controls 
are not created again the event will not trigger.

Hope to find a good solution, till that time I will add the less nice 
option of an button to save.

Regards,
Jeffrey


> Jeffrey,

	Do you mean like when you close the browser you expect
Page_Unload
to fire?  If so, its not going to happen.  Once a page is served to a
client, that's it - end of story.  The server doesn't get a response
from
the client on any other action, whether its to close the browser, reboot

the
machine, go to another site - nothing.  Your Page_Unload actually fires 
when
ASP.NET has finished all of its other actions with the page (like load
postback data, load viewstate, load, render, etc).  You can use the
Page_Unload to do things like clean up or reset various objects you need

for
other pages, but don't use it to save data.  Instead, consider making a 
save
button on the page that when clicked fires an event that calls your
writeData.

- Chuck

-----Original Message-----
From: Jeffrey Tournier [mailto:jeffrey.tournier@v...]
Sent: Monday, July 08, 2002 10:32 AM
To: ASP+
Subject: [aspx] Page_Unload will not execute


Dear you,

I'am creating an ASP page which contains data in a dataset. This dataset

is connected to a couple of textboxes. I want to be able to edit het
data 
in the textboxes and when I leave the page I want to use the Page_Unload

to save my data to the dataset. 

This dataset will be kept in the Session so I can use it on the next
pages.

I'am using VB as programming language.

Here is the Page_Unload I'm using:
Private Sub Page_Unload(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles MyBase.Unload
        writeData()
End Sub

Can anyone help me with this?
I read an article from september 2001 where a solution for C# was
provided 
but this did not work. I don't know if it worked for Eirik then!

Regards,
Jeffrey






  Return to Index