469,964 Members | 1,754 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

Javascript onunload to prompt saving info

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
Nov 18 '05 #1
3 2082
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>
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Weston Weems" <an*******@discussions.microsoft.com> wrote in message
news:6e****************************@phx.gbl...
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

Nov 18 '05 #2
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".

-----Original Message-----
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>
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Weston Weems" <an*******@discussions.microsoft.com> wrote in messagenews:6e****************************@phx.gbl...
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

.

Nov 18 '05 #3
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;

-----Original Message-----
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>
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Weston Weems" <an*******@discussions.microsoft.com> wrote in messagenews:6e****************************@phx.gbl...
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

.

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Brian | last post: by
2 posts views Thread by Luke - eat.lemons | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.