473,569 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Frinavale
9,735 Recognized Expert Moderator Expert
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 2094
phvfl
173 Recognized Expert New Member
What does _myMethod return. The OnBeforeUnload event is usually used by assigning a string value to the event.returnVal ue 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 Recognized Expert Moderator Expert
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....th e 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
1392
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" of the browser or on the keyboard clic "ALT+<left>", to advice he that executing this action he will loose all the steps he has done till there. ...
3
2429
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 execute a function on the form. Is this possible? Thanks, Scott
5
2444
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 enlarges the map, I want to hide my navigation table etc, maximising the viewing area. I've been working on this for 5 hours now, so far I have as...
0
2234
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. Any help would really be appreciated. Thx
2
5743
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 browser window. Is there a way to postback and call a server-side function when this happens? I am aware of the browser's native "onunload" event,...
1
9729
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
4
2463
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 about 0.5 seconds, then calculate how much time to sleep until the next collection. The problem is that when I cancel the collection, I have to...
4
4788
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 completes it invokes a method from the calling thread. Sort event driven concept with threads. Thanks. Ed Gomez
1
2001
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 submitting this form."); }
9
3243
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. Example function test (int a, int b);
0
7694
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...
0
7609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
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. ...
1
7666
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...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3651
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...
1
2107
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
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
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...

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.