Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run code before leaving

Status
Not open for further replies.

aTekTipsUser

Programmer
Nov 8, 2004
68
US
In asp.net, I am trying to run code before leaving the page. I've tried using window.onbeforeunload to ask the user if they want to save. If they say yes, I mark a hidden checkbox, and re-submit the form. Then, on the page_load event, I check to see if the hidden checkbox is checked and if it is I save to the database. This worked fine running on my system, but when I posted it live on the web, it did not work, it did not update the database. Any ideas on how to save to a database before leaving the page? I want this code to run whenever the users click the x to close the window or the back button. Thanks in advance.
 
There is no reliable way to determine when a user is leaving the page. They could close the browser, use the Task Manager to kill the browser process, or just shut off their PC or modem.

You'll need to implement a Save button.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
And a good example of that can be found at:


--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top