473,386 Members | 1,908 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,386 software developers and data experts.

Calling a method that's part of an object during the onbeforeunload event.

Frinavale
9,735 Expert Mod 8TB
I'm not sure what I'm doing wrong.

I am attempting to configure my object so that the object's method is called during the onbeforeunload event of the page.

I have it so that it calls the method during the begin request of an Ajax call to the server...I don't know why I can't get the onbeforeunload event to work

Here's what I have (I'm using the Ajax.NET library):
Expand|Select|Wrap|Line Numbers
  1. MyNamespace.MyClass = function(element) {
  2.     MyNamespace.MyClass.initializeBase(this, [element]);
  3.  
  4.     this._onBeginRequestHandler = Function.createDelegate(this, this._onBeginRequest);
  5.     this._onEndRequestHandler = Function.createDelegate(this, this._onEndRequest);
  6.     var prm = Sys.WebForms.PageRequestManager.getInstance();
  7.     prm.add_beginRequest(this._onBeginRequestHandler);
  8.     prm.add_endRequest(this._onEndRequestHandler);
  9.  
  10. // Here is what is not working
  11.         window.onbeforeunload = this._myMethod;
  12. //I have also tried the following but it doesn't work either:
  13. //      window.onbeforeunload = this._onBeginRequestHandler;
  14. //since the _onBeginRequestHandler method just calls _myMethod anyways.
  15.  
  16. }
Thanks,

-Frinny
Mar 31 '10 #1
2 2084
phvfl
173 Expert 100+
What does _myMethod return. The OnBeforeUnload event is usually used by assigning a string value to the event.returnValue property which is then displayed in an exit page prompt. So the following would show a dialog with the message "Page close prompt"
Expand|Select|Wrap|Line Numbers
  1. function pageClosing(e){
  2.   // For most browsers
  3.   e = e || window.event;
  4.  
  5.   // Ensure that the event object is not null
  6.   if(e){
  7.     e.returnValue = 'Page close prompt';
  8.   }
  9.  
  10.   // For browsers that don't support the returnValue property.
  11.   return 'Page close prompt';
  12. }
  13.  
  14. window.onbeforeunload = pageClosing;
  15.  
The prompt typically has an OK and Cancel button - OK exits the page and Cancel prevents the window closing. The prompt can not be interacted with from within script.

If you perform an AJAX request within the function it should start but the result may not be processed if the page is exited.

Hope this helps
Mar 31 '10 #2
Frinavale
9,735 Expert Mod 8TB
Thanks for the info but I already have a good idea about how the onbeforeunload event works ;)

The method does not return anything so the Ok/Cancel prompt is not displayed....the method displays 2 <div> elements that prevent the user from accessing the controls on the page while a request to the server is being processed.

I'm not sure why I can't seem to call the method that belongs to the object during the onbeforeunload event....

-Frinny
Mar 31 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Fabri | last post by:
I would like to have a "confirm" from my users this way: For example a user browse a page and click some link, the history contains now something. I would like, if the user click "BACK BUTTON"...
3
by: Scott Schade | last post by:
I have a form onto which I add a control during execution. The control is a control that I wrote. The control has a number of controls on it. I would like to click on a button on the control and...
5
by: Simon Harris | last post by:
Hi All, I am trying to call a method in a web form, from an event fired in a user control. My user control displays a map, which has a link button to enlarge/shrink the map. When the user...
0
by: Cleo | last post by:
Hi, I am trying to call a WebService Method written in Weblogic from VB.NET and I am getting the following error. I am using SOAP Caal s from VB.NET. Please find the wsdl file and my code. ...
2
by: M B HONG 20 | last post by:
Hi all - I am developing an ASP.NET (C#) application and need some help. I wish to call a server-side function (in the code-behind "file.aspx.cs") upon a user clicking on the "X" to close the...
1
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...
4
by: barker7 | last post by:
In our app, we need to collect data at regular intervals (4, 8 or 16 seconds - user settable). The collection happens in a background thread. My first approach was to do the collection, which takes...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
1
by: ramgaikwad | last post by:
<script> function checkFormStatus(oForm) { if(isDirty(oForm)) //event.returnValue = "You have entered form Data without submitting this form."; { alert("You have entered form Data without...
9
by: Pubs | last post by:
Hi all, I want to call a function with some intial parameters with in a thread. At the end of the function execution it should return a value to the caller. Caller is outside the thread. ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.