Object modified warning on browser close/navigate away.

Object modified warning on browser close/navigate away.

Old forum URL: forums.lhotka.net/forums/t/7194.aspx


lektira posted on Tuesday, June 30, 2009

The scenario I want to achieve is the following:
1. User goes to a page, which contains a writable businessbase object.
2. User modifies one or more fields of the objects, including the collections.
3. User closes the browser, or navigates away.

Here, I would like to have captured the IsDirty property of the object or any other indication that will allow me to prompt the user reminding them that the object is not saved.
I store the underlying object in the session, but the IsDirty property remains false. Could anyone please help me with this. Are they some event handlers on the datasource and its collections?
In a windows application, it was much more straightforward, but in a Web application is a pain.
Thanks a lot!

lektira

ajj3085 replied on Tuesday, June 30, 2009

I used javascript, jquery and some server controls. Basically i initially set a javascript global variable isDirty. Using jquery, I hook into the various form inputs Changed or Clicked events to also update that variable.

On any link or button, i called a method that would return true or false. If dirty wasn't set, it just returned true... otherwise it threw up a confirm asking if the user wanted to leave. You might be able to handle the browser closing on handling the pages unload event, but I don't think you'd be able to stop it..

Copyright (c) Marimer LLC