Well, since you're using JavaScript already in your solution you are probably aware that this solution will require JavaScript.
You're going to have to write a function that will keep track of any changes that happen to your controls.
You are going to have to set every control on your page to call this when a change occurs....so for every TextBox, set it to call the function that tracks changes during the onkeydown event...for every DropDownList, set it to call the function during the onchange event......etc etc.
Some controls (like calendars) will postback to the server when they are changed...so the server needs to be able to be able to indicate that a change has been made as well. Therefore, you'll probably have to store the boolean value that indicates whether or not changes have been made in a HiddenField so that it is available in both the server and client side code.
You can use the
onbeforeunload JavaScript event to let the user cancel leaving your page.
So, the onbeforeunload event will have to call a function that retrieves the boolean value that's being used to track changes.
The onbeforeunload event happens
every time the page is about to unload. This means that it happens any time a full page postback occurs.
Therefore all of your buttons, links, and anything else will have to indicate that the page should be unloaded without prompting the user.
So you need another function that registers any control that posts back to the server.....
So really, the method that handles the onbeforeunload event will have to check if any changes have been made, and check if any of your controls caused the page to unload before deciding whether or not to prompt the user.
Happy coding
-Frinny