473,699 Members | 2,386 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a code behind function on onbeforeunload event

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

my body tag - <body onbeforeunload = "X_close()" >

Javascript - function X_close( ) { if ( window.event.cl ientX < 0 ||
window.event.cl ientY < 0) { alert("test") } }

Is there a way I can call Cleanup func from X_close func? or is there
some other way to do this.. Any help appreciated!!!! !!! Thanks!!!

In my post back I have the code below. but this doesn't work.... It
should work I think.

Dim Script As String

Script = "<script language=""java script"" type=""text/javascript"">"

Script &= "function X_close() { alert(""KKKKK"" );}"

Script &= "</script>"

If (Not IsClientScriptB lockRegistered( "clientScript") ) Then

RegisterClientS criptBlock("cli entScript", Script)

End If

Cleanup function ( vb.net)

Private Sub Cleanup(ByVal LineID As Integer)

Dim resourceData As New ResourceMateria l

resourceData.cl eanup(LineID)

End Sub

Sep 25 '06 #1
1 9743

le********@hotm ail.com wrote:
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

my body tag - <body onbeforeunload = "X_close()" >

Javascript - function X_close( ) { if ( window.event.cl ientX < 0 ||
window.event.cl ientY < 0) { alert("test") } }

Is there a way I can call Cleanup func from X_close func? or is there
some other way to do this.. Any help appreciated!!!! !!! Thanks!!!
[snip]

Yes it's possible. Of course you would also know that vbscript would
only work on IE. But anyways, the following example shows that it
works:

<html>
<head>
<title>exampl e</title>
</head>
<body>
<script type = "text/vbscript">
function vbFunc()
document.write( "vbscript")
end function
</script>

<script type = "text/javascript">
function jsFunc()
{
document.write( "javascript ");
}

vbFunc();
</script>
</body>
</html>

Please make note of the order that they're in. The vbscript must come
first before you are able to call the function. Tested in IE6.

Sep 25 '06 #2

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

Similar topics

6
23118
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!
4
4081
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is dependant on data collected in the code behind on the server. I have set AutoPostback to false for the controls and added lines such as cboMyCombo1.Attributes.Add("onchange", "MyCombos_OnChange('1')"); in the Page_Load event, which is rendered OK...
6
2438
by: SP | last post by:
Hi, I want to add wait cursor code whenever page is post back. Page may be post back on my user control's or on change of dropdown or on click of any button on page. so is there any common solution available that will provide me mechanism to display wait cursor or wait image to user whenever page is post back to server? Thanks,
2
5757
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, but am not certain that what I'm looking for is actually possible. Any help would be greatly...
0
2385
by: teddysnips | last post by:
I have Search form that allows users to retrieve records into a DataGrid. There are two search criteria - a Month and a Year, which are selected from drop-down lists. There is a server-side button called "cmdFilter" which retrieves data from the database using any criteria thus selected. For any of the records retrieved into the grid match certain conditions, one of the columns will be formed into a hyperlink. Clicking on this will...
0
1836
by: teddysnips | last post by:
I have Search form that allows users to retrieve records into a DataGrid. There are two search criteria - a Month and a Year, which are selected from drop-down lists. There is a server-side button called "cmdFilter" which retrieves data from the database using any criteria thus selected. For any of the records retrieved into the grid match certain conditions, one of the columns will be formed into a hyperlink. Clicking on this will...
8
7572
by: drewmania001 | last post by:
im currently using the following to prompt the user before navigating away from the page // add an unload event window.onbeforeunload = bunload; // function to prompt user function bunload(o){ return false; }
1
2008
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."); }
0
8685
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
9172
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...
1
8908
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
8880
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7745
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...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4374
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...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3054
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

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.