Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Fire event when user leaves a .aspx page

Posted on 2011-03-15
1
Medium Priority
?
838 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 500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

636 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