By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,516 Members | 1,176 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,516 IT Pros & Developers. It's quick & easy.

Calling a code behind function on onbeforeunload event

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.