Solved

Fire event when user leaves a .aspx page

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

18 Experts available now in Live!

Get 1:1 Help Now