473,651 Members | 3,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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= "__doUnloadPost Back()"
language="javas cript">
<script language="javas cript">
<!--
function __doUnloadPostB ack() {
var theform;
if (window.navigat or.appName.toLo werCase().index Of("netscape")
-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
1 3445
"Richard \(MrBonus\)" <wh********@hot mail.com> wrote in message news:<ch******* ***@news.cyberc ity.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.valu e.indexOf("*") >= 0)
{
alert(messageTe xt);
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.natAValidWe bAddress.com"
method="POST"
onsubmit="retur n 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6733
by: Robert Oschler | last post by:
I have a web page where I want to make sure that an image HTTP request is successfully made before the page unloads. The request is made by setting the image element's SRC property to the desired URL. When I put the SRC property change in either an "onbeforeunload" or "onunload" event handler, the HTTP request is not received by our server as much as 75% of the time. I thought of setting a flag using an "onload" handler for the image...
1
3890
by: Robert Oschler | last post by:
I've successfully attached to the "onclick" and several other events using AttachEvent(). But when I try to attach to the "onbeforeunload" event it doesn't work (the handler I've assigned is never called). Is there something different about this event? Is there another way to attach to this event that would work, other than manually filling in the <BODY> tag with an 'onunloadbefore' assignment? thx
1
5672
by: rufus | last post by:
I have a function that checks whether the user is trying to navigate away from the page before saving all their data. I achieve this using the window.onbeforeunload javascript event. It fires when somone clicks on a link or button but not when someone changes the selected index of a dropdownlist or radio button. I tried registering the following script: RegisterOnSubmitStatement("submit", "confirmClose;") but it does not fire when a...
6
23096
by: jennyw | last post by:
Hi, I'd like to use onbeforeunload to submit a form before leaving a page. This works in Firefox and IE. Safari, however, blithely ignores this. Does anyone know of a workaround for Safari? Or another way to do the same thing in Safari? (that is, intercept a request to leave the page). I tried Safari 2.02 on Tiger. Thanks!
1
9739
by: lee_youjin | last post by:
I needed to defect when the user is clicking the IE X button ( top right). so I could execute the cleanup function. I was able to detect it using onbeforeunload event. Now I need to call the function in code behind from onbeforeunload event call. but that is where I have a problem... please refer my code below
2
3486
by: Pete Verdon | last post by:
Hi, I'm working on a substantial AJAX-type application. The latest feature I've added is the ability to append a query string to the end of the normal URL, which will cause the application to open a new tab (within itself, not a browser tab) according to the contents of this string, alongside the normal tabs it provides. This all works as expected. What I would now like to do is provide the ability to open a second such tab alongside...
5
9691
by: allan.young | last post by:
Hi, When in gmail I'm composing a new email message and I bit the browser back button, I get a dialog that says "Your message has not been sent. Discard your message?" But if instead of clicking Back, I hit the Browser Close button, I get the above message, PLUS if I click "cancel" on that dialog, I get the following message 'Are you sure you want to navigate away from this page? Press "Cancel" to remain on this page. Press OK to...
1
108719
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back button anyways, if the user ventures away from your page then they wouldn't have this button at their disposal. The main reason people ask how to control or disable the back button is because they have a need to control sensitive (and/or) dynamic web...
0
8367
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8703
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8467
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4145
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2703
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.