about the event of page.unload

Hi all,

I have got a code to handle the event when the user is leaving a page (say aaa.aspx) and go to another page (say bbb.aspx). Here is a sub routine of "unload" in aaa.aspx. 

Private Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Unload

//Codes.....do sth to dispose the object when leave out from the page.

End Sub

I expect that only when users go to another pages, this sub routine will be triggered. The problem is that whenever the page of "aaa.aspx" is being loaded, initialized or postback. This event is always triggered. Do u know why?

 Thank you,

 Marco

0
lamchichiu_marco
12/12/2008 8:42:47 AM
asp.net.migrate-vs2003-vs2005 590 articles. 0 followers. Follow

3 Replies
912 Views

Similar Articles

[PageSpeed] 20
Get it on Google Play
Get it on Apple App Store

Hi,

it's default behavior since it's a part of the Page Life Cycle.

What are you exactly trying to do with the code? A possible solution would be to postback to the page, after a button click or so, and in the click event execute the code you want and then navigate away to your other page by using the Response.Redirect("myotherpage.aspx") method.

Grz, Kris.


Read my blog. Handy Firefox plugins for web developers.


Workaround for non working Mark as answer buttons.
0
XIII
12/12/2008 11:44:37 AM

lamchichiu_marco:

Hi all,

I have got a code to handle the event when the user is leaving a page (say aaa.aspx) and go to another page (say bbb.aspx). Here is a sub routine of "unload" in aaa.aspx. 

Private Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Unload

//Codes.....do sth to dispose the object when leave out from the page.

End Sub

I expect that only when users go to another pages, this sub routine will be triggered. The problem is that whenever the page of "aaa.aspx" is being loaded, initialized or postback. This event is always triggered. Do u know why?

 Thank you,

 Marco

Hi,

Page_Unload doesn't work in the way you think it does.  It's NOT fired when a user leaves the page, it's fired as the last part of the page lifecycle:

Page_Init
Page_Load
Page_DataBind
Page_PreRender
Page_UnLoad

"Page_Unload: After a page has finished rendering, the Page_Unload event fires. This event is a good place to perform final cleanup work. This includes items such as the cleanup of open database connections, discarding objects, or closing those files that are open."

0
Mr
12/12/2008 12:19:18 PM

Thank a lot!

 Actually I 've a crystal report viewer in my page. I hope to dispose the crystal report when the user leaves from the related page. I have got no idea in this issue.... Would you like to do me a favour?

 Thanks.

 Marco

0
lamchichiu_marco
12/15/2008 1:10:43 AM
Reply:

Similar Artilces:

Upgrade/migration issues from VS2003+.NET 1.1 to VS2005+.NET 2.0
Hi,  Visual Studio is great when everything works well and you don't know what is happening under the hood. However when things don't work it is really frustrating since you just don't know what is going on.  I have a project (a web site) that was originally developed for VS2003 and ASP.NET 1.1. When I loaded this project on VS2005 (and ASP.NET 2.0), VS told me that it will migrate it to the new environment: it did a number of things, generated a migration report and created/moved files under App_code and such directories. I tried this process a number of times b...

Getting next page address on unload event of page. Possible?
suppose a user is on www.xyz.com (my web page) now the user types in address bar www.yahoo.comis it possible to get the next visiting url ie www.yahoo.com when the unload event of www.xyz.com fires.Thanks.   Aseem \../ (-_-) \./ Gautam"You Dont know when the end is, But its Coming Fast" Nope. Eric Pascarello.com | Twitter epascarello | LinkedIn No...way...

Page.UnLoad Event
I'm trying to make my webform to some final processing when the user exits (closes the browser window). What I did is to declare an eventhandler for Page.UnLoad and when that was fired my Page_hasunLoaded(Object sender, EventArgs e) method was supposed do the processing. My "application" (simplified) consist of a Login page which (if login&password correct) redirects me to the page I am talking about. But exactly when the Login page redirects me THEN the event gets fired. Nothing happens when I close the browser window. I don't understand how Page.unLoad gets fired when I'm ...

Page Unload event
Hi; When the user presses Back button or do something else to cause the page unload I want to show a message box to ask the user "Are you sure to exit?" Is there a way to get into Page_Unload event ? Thank you for your replies... bad idea :-). You cannot show a messagebox from serverside code. Add a handler to the clientside onclose event, and ask user there. It will look like this: <script language="javascript"> function closeConfirm() { return confirm("Are you sure ?"); } </script> <body onclose=&quo...

Migrate from VS2003 to VS2005
Hello, please help me with my problem. Projects were successfully migrated from 2003 to 2005. I have VS2005 Team Edition, installed: VS80-KB898904-X86-ENU.exe, VS80-KB915364-X86-ENU.exe, WebApplicationProjectSetup.msi. I tried to open solution. At first I couldn’t open solution at all I have done the next changes: “You will need to change the MSBuild targets in the project file. Open this file with a text editor and replace the VSTO target with this one <Import Project="$(MSBuildExtensionsPath)\Microsoft.VisualStudio.OfficeTools.targets" />”. Now I can open solution but...

Migrating VS2003 to VS2005.
Hello, I have recently migrated VS2003 web application(ASP.NET 1.0) to VS2005 (ASP.NET2.0). But after migration I am getting an error saying a particular DLL is not defined. How do I register this DLL in the server so that I can overcome this problem. Note: I have migrated the application which is in different machine(i.e., Shared drive).   Thanks, Renil. You don't have to register the dll on the server.  Just put it in your App_Code folder  and then add a reference to it in Solution Explorer.http://msdn2.microsoft.com/en-us/library/1886a4bb-c9d8-4ba6-8078-04b...

Master Page's Page Load firing twice on events called from other Page events
I have numerous pages tied to my MasterPage that controls 2 Always visible extenders for User Reminders and a Counter. I would like them to only fire on a Page_Load once, not twice. I have read a million posts about AutoEventWireupset to false, but on all my pages it is set to true and on those pages the events only fire once. The Master page is giving me problems on events firing twice. Any suggestions? here is some code... protected void Page_Load(object sender, EventArgs e) {if (!Page.Master.IsPostBack) {  I call 2 stored procedures here that should only fire once on a Page_Lo...

Page Unload Event does not Fire
I'm having a problem firing page unload event. If I make use of a button which moves to another page when clicked, the unload event is fired successfully. However, if the trigger is coming from a user control which contains a datalist of links pointing to other pages... the problem now comes in. It doesn't seem to fire the page unload event anymore. I need to store some values before leaving the page thus I need to make this event work.By the way, I'm implementing it using C# & this is a web application.Is there any workaround and explanation for this?Your help would be greatly...

almost page unload event
hello folks...I've got this problem and i googled it but couldnt find the suitable solution , I have some sharing application , and I added subscribe feature to it , and there is a function to send emails , anyway...I have 4 fileupload controls in the upload page , and I want that when users finishes uploading , an email is sent with each file name , the code seems not that hard , but how to know when the user finished uploading?! I read a post saying it's impossible to know when , as there is postback which has the unload event but it doesnt mean leaving the page cause it might be a...

Page unload event #2
When the user clicks on the close button of the web form ( the (x) button on the top right corner) , I need to perform some operations, I have wriiten the code in the page _unload event and page_disposed evnt , but it doesn't work ,I have also tried with the application end and session end of the global.asax file, but it isn't workingSo where do i write this functionality ?Could anyone help me pls? Manjula I take it that you're referring to the server-side Page_Unload event. This is fired before the page is rendered into the browser. You'd need to do this client-side through...

Migrating a VS2003 project to VS2005
I need to migrate a web project from VS2003 to VS2005. I am a novice user. List down the steps that need to take care before migrating. Is there a tool (don't want that tool in VS2005 setup) that will migrate my solution to 2005 hassle free? Thanks! Viswanth V.G Check out this article:Step-By-Step Guide to Converting Web Projects from Visual Studio .NET 2002/2003 to Visual Studio 2005 Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! Great link... Thanks a ton! My problem is to convert all the *.vb code files to Partial classes. ...

Migrating RDS pages to .Net
I have an existing ASP intranet application that we are looking to migrate to ASP.Net.  Many of the pages in this site use RDS to allow client-side manipulation of the data (sorting, filtering, etc) without having to make a round trip to the server.  Is there an equivalent capability in ASP.Net? TIA Ron L   rlounsbury:Many of the pages in this site use RDS to allow client-side manipulation of the data (sorting, filtering, etc) without having to make a round trip to the server.  Is there an equivalent capability in ASP.Net? What you are talking about is the use of A...

Catching Page Unload Events
Hello all, I am working on a project which has multiple forms based on a single master page in VB.NET with Visual Studio 2005 ASP.NET 2.0.  On the Master page are various links which allow the user to postback to that particular page.  However some of the forms have multiple steps.  Such as adding an Industry and then adding categories to that industry to an Access 2003 database.  I am trying to guard against the user's ability to redirect to one of those other page links on the master page in middle of the data input process, which could lead to parent tables not hav...

Detecting PostBack Event in Page Unload
Hi, I have a web form which updates a database.  When the page is loaded, the database record is read and bound to the form controls as usual. However, it is a multi-threaded application and the database record needs to be locked (pessimistic - it has to be done this way as optimistic will not work in this situation).  So, as well as reading the data when the page is loaded, a bit is flipped on the database row using an "UPDATE" stored procedure. If the user updates the record, or clicks on a cancel button, the database row is unlocked using a similar stored procedure.  How...

Web resources about - about the event of page.unload - asp.net.migrate-vs2003-vs2005

Interpublic Group Unloads The Rest Of Its Stake In Facebook
... in 2006 for a stake in Facebook. After selling about one-half of that stake to an undisclosed buyer in August 2011, for $133 million, IPG unloaded ...

Campaign to Unload (@Campaign2Unload) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

All sizes - Day 066/365 - Unload Seniors Here - Flickr - Photo Sharing!
Flickr is almost certainly the best online photo management and sharing application in the world. Show off your favorite photos and videos to ...

UK press unload on Rabbitohs code-hopper Sam Burgess
The finger-pointing is underway after Sam Burgess ended his ill-fated stint in rugby union and decided to return to the NRL.

Zuckerberg unloads Facebook shares (00:54)
In a bid to pay of his taxes, Facebook founder and CEO Mark Zuckerberg is selling 41.4 million shares worth $2.61 billion.


Father unloads on police over drive-by shooting
An irate Canberra father says ACT Policing fell well short of the mark in its response to a drive-by shooting in Kambah.

Mitchell Starc returns as David Warner unloads in Indian Premier League
David Warner has continued his magnificent Indian Premier League form, blasting a superb 91 as his Sunrisers Hyderabad to a 16-run victory in ...

Waratahs captain Dave Dennis unloads on profligate side
The Waratahs are in danger of repeating the sins of last season if they do not sharpen up in attack quick smart.

Roy Keane unloads on Arsenal - 'obsessed with selfies and six-packs'
Former Manchester United midfielder launches withering attack on Wenger's side - and takes a shot at Man City too

Resources last updated: 12/15/2015 1:58:25 AM