473,406 Members | 2,894 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,406 software developers and data experts.

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.clientX < 0 ||
window.event.clientY < 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=""javascript"" type=""text/javascript"">"

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

Script &= "</script>"

If (Not IsClientScriptBlockRegistered("clientScript")) Then

RegisterClientScriptBlock("clientScript", Script)

End If

Cleanup function ( vb.net)

Private Sub Cleanup(ByVal LineID As Integer)

Dim resourceData As New ResourceMaterial

resourceData.cleanup(LineID)

End Sub

Sep 25 '06 #1
1 9711

le********@hotmail.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.clientX < 0 ||
window.event.clientY < 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>example</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
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...
4
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...
6
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...
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...
0
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...
0
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...
8
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...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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
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...
0
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...

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.