473,385 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 2237
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Gord | last post by:
Hello, If you set the flag for an overwrite prompt using the 'Save' common dialog, how do you read the response when the user clicks the Yes or No in the 'overwrite' message box? Everything...
2
by: Michael | last post by:
I am reading and setting a cookie using JavaScript in the BODY onload and onunload events respectively. This works fine. However when I use ASP to set the cookie under some condition where I...
3
by: Brian | last post by:
Hi I'm trying to get a small script working I need to get the user to input some info from a prompt and then use that info in a PHP script, but I can't seem to assign the JavaScript var to a...
2
by: Luke - eat.lemons | last post by:
Hi, I have this function: <script type="text/javascript"> function disp_prompt() { var reqid=prompt("Please enter the membership ID number","") if (reqid!=null && reqid!="") { reqid=reqid }
1
by: vinya | last post by:
<html> <head> <script type="text/javascript"> var element; function test(){ abc = document.getElementById('promptbox').value; document.forms.elements.value = abc; ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.