Solved

Fire event when user leaves a .aspx page

Posted on 2011-03-15
1
821 Views
Last Modified: 2012-05-11
I need to fire an event when a user leaves a page.  I tried page unload, but fires even when the page loads.  I tried page dispose, but it does not fire at all.
I need to update the database in this event.
0
Comment
Question by:rrhandle8
1 Comment
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 125 total points
ID: 35143038
Hi,

You have to understand that one thing are SERVER SIDE code and events, and another thing are CLIENTE SIDE code and events.

When you said that Page Unload fires even when the page loads it is because is the normal Page life cycle (look the link below)

http://msdn.microsoft.com/en-us/library/ms178472.aspx

So, if what you want is to call SERVER SIDE code and events, when the user Leaves/Close/Navigate to another page you have to do it in CLIENT SIDE code and events, using javascript  onbeforeunload event, where you can call a webservice to update your database.

But you cannot run SERVER SIDE code of the page the user is leaving since you will have to LOAD  that page again

Remember, it is possible for the user to suddenly lose their internet connection, their browser could crash, or switch off their computer using the big red switch. There will be cases where the server simply never hears from the browser again, so keep this in mind cause not always you will be able to reach the server when the user leaves a page
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question