Hi Gordon,
>> 1. Detect the user has navigated away from the update page, they may have pressed the browser back button or closed the tab, unfortunately I don't know how to do this
The short answer is "you can't" -since they could just terminate the browser program, or turn off the computer. This is the inherent danger with locking records as you are doing, and why I'm not a fan of your approach.
the longer answer is that you could create a websocket connection to the form, then detect when that connection times out (if the page disappears, it'll time out on the next internal ping). I fear this may be difficult for you at this stage though as there would be quite a lot of embed code, and a bit of javascript, to match up a sock to a lock.
>> 2. I add a SessionID and DateTimeStamp to the lock records, so I can have a housekeeping task that clears old locks,
yes, this is likely better, and easier
>> However I would like to also check for locks with sessionids that are no longer active in case any tidy up was missed.
there's a method in WebHandler, called NotifyDeleteSession which you can embed code into so you can do things when a session is deleted. You should also note the NotifyChangeSession as well as Session ID's can change. If you are using a table to store this data there are template options in WebHandler where you can specify the table, and the Change and Delete will be done for you.
Cheers
Bruce