This functionality just works and is not related to Visual Studio whatsoever. In your question, you are mixing somethings up, I don't know why.
Also, it is not apparent that you really need
onebeforeunload
, maybe you can use
onunload
instead. Please see:
http://msdn.microsoft.com/en-us/library/ie/ms536907%28v=vs.85%29.aspx[
^].
You only needs
if you need to stop the user from navigating from your page (which is usually not very nice, by the way, but you can ask users confirmation and still allow to leave the page if the confirmation is given). See also this discussion:
http://stackoverflow.com/questions/3775566/javascript-question-onbeforeunload-or-onunload[
^].
—SA