Solved

Fire event when user leaves a .aspx page

Posted on 2011-03-15
1
808 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

815 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now