By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,265 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

onBeforeUnload doesn't work quite the way I want it too

P: n/a
the code is taken from my asp.net page. (written in C#)

Hi, im trying to make my page postback before the it unloads, i've tried a
lot of stuff, and finally I made something that worked, the problem is the
alert in the code -- alert('TittyX'); --. If I remove it, then it doesn't
work, well the method runs fine, but I can't catch the --
theform.submit(); --.

Another weird thing, is I can only catch the event in the Page_Load event on
the server, which is weird, but I can live with that, what I can't live with
is the alert.

Anyone who knows either another solution, or can tell me what I should do to
make it work?
<body MS_POSITIONING="GridLayout" onbeforeunload="__doUnloadPostBack()"
language="javascript">
<script language="javascript">
<!--
function __doUnloadPostBack() {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("n etscape")
-1) {

theform = document.forms["Form1"];
}
else {
theform = document.Form1;
}
theform.submit();
alert('TittyX');
}
// -->
</script>

<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 184px; POSITION:
absolute; TOP: 120px" runat="server" Text="Button"></asp:Button>
</form>
</body>
Richard

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Richard \(MrBonus\)" <wh********@hotmail.com> wrote in message news:<ch**********@news.cybercity.dk>...
the code is taken from my asp.net page. (written in C#)
When posting to this forum, it is best to go into the web browser and
post a copy of the gernated code. Folks like me do not know asp nor
C#.

Hi, im trying to make my page postback before the it unloads, i've tried a
lot of stuff, and finally I made something that worked, the problem is the
alert in the code -- alert('TittyX'); --. If I remove it, then it doesn't
work, well the method runs fine, but I can't catch the --
theform.submit(); --.


I suspect that you have a timing problem. I have read where there may
be a timing problem when you cancel the page after submitting the
page.

Here is an example of doing some validation on the client then
submitting the form if validation is successful.

I tried this on IE and Netscape on MacOS 10.2.6.

Robert

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head>
<title>Check form fields</title>

<script type="text/javascript">

function validate()
{

var x = document.forms["myForm"];
var submitOK = true;
var messageText =
"What a suprise! Please correct the error in your ways." +
" Please remove the asterisk ( * ) in the name field.";
if (x.theName.value.indexOf("*") >= 0)
{
alert(messageText);
submitOK = false;
}

return submitOK;

}

</script>

</head>
<body>
<p>
This html file shows how to cancel a submit.
To cancel the submit, place an asterisk ( * ) in the name field.
</p>
<form name="myForm"
action="http://www.natAValidWebAddress.com"
method="POST"
onsubmit="return validate();">
<p>Name:<br>
<input type="text" name="theName" size="20"><br><br>
<p><input type="submit"></p>
</form>
</body>
</html>
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.