When a user is using a Detailsview or Formview in Edit mode, and tries to leave the current page, I want to trap this and force any changes to be saved, just as if the user had clicked on the Update LinkButton. How can I do this?
Asp.net force save on detailsview/formview
You can't do this reliably. Consider the scenario if their computer crashes altogether, or they kick the power cord out. There's so many ways that a user can leave a page.
However, you could put in a few safeguards. On any link on the page you could hook up events to do the save before they left. You could also try doing a save after every change in control focus perhaps.
Another thing you can do is hook into the window.onbeforeunload event and give them a confirmation message asking if they're sure they want to leave the page, like SO does when you have an unsaved answer. But there's nothing you can do with this event to force a save.