Solved

Fire event when user leaves a .aspx page

Posted on 2011-03-15
1
825 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Easy filter aspnet 2 46
reading excel file in .net 2 45
vb.net convert long time to mm:ss 23 32
bulk load multiple users for aspnetusers table 2 11
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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 interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

738 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