473,385 Members | 1,546 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.

OnUnload of a web form

Ok,

what I am attempting to do is take a web form and attach a
confirm to leave page. I can get the event to fire (though
it doestn actually prevent navigating away from the site)

My problem is that every time I initiate a postback, the
event is also fired. I dont want people to see "Are you
sure you wish to discard any changes?" if they hit refresh
or postback etc.

ANyway I can get around this?
Nov 18 '05 #1
3 1434
"Weston Weems" <an*******@discussions.microsoft.com> wrote in message
news:62****************************@phx.gbl...
Ok,

what I am attempting to do is take a web form and attach a
confirm to leave page. I can get the event to fire (though
it doestn actually prevent navigating away from the site)

My problem is that every time I initiate a postback, the
event is also fired. I dont want people to see "Are you
sure you wish to discard any changes?" if they hit refresh
or postback etc.

ANyway I can get around this?


You can't really do this. Remember that by the time the client sees the web
page, the code has finished on the server. Once the page has been sent to
the client, the server has no further connection to the client, and cannot
know when the client closes his browser.

All of this sort of thing has to be done on the client, in script.

John Saunders
Nov 18 '05 #2
Thats what I am doing...

<body onUnLoad="confirm_method();"> etc...

I dont mind using clientscript... my problem is that
postbacks cause the onUnLoad to fire off.

Maybe in onunload, I'll check querystring and if its not
my site, confirm leave.

-----Original Message-----
"Weston Weems" <an*******@discussions.microsoft.com> wrote in messagenews:62****************************@phx.gbl...
Ok,

what I am attempting to do is take a web form and attach a confirm to leave page. I can get the event to fire (though it doestn actually prevent navigating away from the site)
My problem is that every time I initiate a postback, the
event is also fired. I dont want people to see "Are you
sure you wish to discard any changes?" if they hit refresh or postback etc.

ANyway I can get around this?
You can't really do this. Remember that by the time the

client sees the webpage, the code has finished on the server. Once the page has been sent tothe client, the server has no further connection to the client, and cannotknow when the client closes his browser.

All of this sort of thing has to be done on the client, in script.
John Saunders
.

Nov 18 '05 #3
you want unbeforeunload(). you will have to put in code that checks that a
submit was done.

<body onbeforeunload="return doUnload()">

<form ....
....
</form>
<script>
var unloadOk = false;
function doUnload() {
if (!unload) return "Lose data changes?";
return;
}
window.__doPostBack = function (eventTarget, eventArgument) {
var theform = document.forms[0];
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
unloadOk = true;
theform.submit();
}
var oldOnSubmit = document.forms[0].onsubmit;
window.onsubmit = function()
{
unloadOk = true;
if (oldOnSubmit) oldOnSubmit();
}
</script>
"Weston Weems" <an*******@discussions.microsoft.com> wrote in message
news:62****************************@phx.gbl...
| Ok,
|
| what I am attempting to do is take a web form and attach a
| confirm to leave page. I can get the event to fire (though
| it doestn actually prevent navigating away from the site)
|
| My problem is that every time I initiate a postback, the
| event is also fired. I dont want people to see "Are you
| sure you wish to discard any changes?" if they hit refresh
| or postback etc.
|
| ANyway I can get around this?
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Simon Wigzell | last post by:
I'm using OnUnLoad in my body statement to redirect to a function to clean things up if someone exits a form by closing it from outside the webpage code - e.g. by not using the cancel or save and...
3
by: =B= | last post by:
Hi all, I was wondering if anyone has had any luck with trapping the <BODY> onUnload() event in ASP.NET? The thing is, I'm writing code for an Intranet site. The code makes a call to a...
1
by: Angel | last post by:
I am trying to capture when the user clicks the X button on the ie window. I have used the onunload for the window event, but there is a problem. I put javascript code for this event and when the...
5
by: jackchang1 | last post by:
I have an application that will submit the form when the page is closed (through onunload event), and it works fine in IE6. But it doesn't work in FireFox, and no data is sent. It seems to me that...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?

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.