Javascript onunload to prompt saving info

W

Weston Weems

Ok,

I've posted on this before, lemme give you guys the run
down. I've got an asp form that has postbacks etc. I'd
like it so that when navigating away from it, It'll prompt
user for save confirmation.

So I've got <body onUnLoad="CheckConfirm();">

The javascript method fires off, and I've got no question
if I could call a remote scripting method to trigger a
save.

My problem is that a postback fires off the javascript
unload event. I tried checking document.location.href, but
thats prior to hitting the button, and being that its not
the new destination url, its more or less impossible to
ignore postbacks.

Anyone found a work around? I dont want to save every
postback, or prompt for a save. (doing so could publically
publish information that could possibly not be ready for
publics eyes)

Thank you very much for the time.
Weston Weems
 
K

Karl Seguin

Weston, the quickest solution I can think of:
<script language="javascript">
var isPostback = false;
function unloading(){
if (!isPostback){
alert('Not caused by postback');
}
}
</script>
<body onunload="unloading();">
<form id="Form1" method="post" runat="server" onsubmit="isPostback =
true;">
...
</form>
</body>
 
W

Weston Weems

Well now, thats an interesting approach, but doesnt
account for refreshes and such. I am curious if theres a
way I can get a reference to the new page or something...


I know if its href is "myurl.aspx" then dont bother doing
anything.

Also, I know its bad bad, but somone calls _doPostback(...
in js explicitly, which I know is badbad, but that also
fires the postback and says "not caused by postback".
 
W

Weston Weems

Actually, I may have jumped the gun a bit on this one...

I understand the theory on this rather well, but what I am
seeing is that if I say hit an edit button on a datagrid,
its saying "Not caused by a postback"

I think because the page in essence reloads itself,
resetting itself back to isPostback=false;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top