Browser close event

G

Guest

In asp.net how to catch window close event when a user closes the window
explicitly by clicking on “x†button which is on the right top corner of the
browser.

My requirement is When a user explicitly closes the window I need to pop up
a message to user and log information in DB whatever the user entered in the
form.

I implemented on Body unload event by calling vb script, but it is getting
executed when I go out of the form by clicking any link or button.

Please see the code snippet

<script language=vbscript>
function fnTest()

dim strCon
dim objConn
dim intTest

Set objConn = CreateObject("ADODB.Connection")
strCon = Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=csa2005;password=csa2005;Initial Catalog=CSA2006;Data Source=UKHPX40701
'strCon = "" & trim(window.form("hdnConn").value) & "" ' this
is from config file
'alert(strCon)
objConn.Open strCon
strSQLupdate = "UPDATE tblEntries set strClientName = '" &
window.form("txtClientName").value & "'," _
& " intCategoryID = " &
window.form("cboCategory").value & ", intSubCategoryID = " &
window.form("cboSubCategory").value & "," _
& " intMarketFunctionID = " &
window.form("cboMarketFunction").value & ", strAuthorizer = '" &
window.form("hdnLPNTID").value & "'," _
& " strHeadLine = '" &
window.form("txtHeadline").value & "', strBackground = '" &
window.form("txtbackground").value & "'," _
& " strInnovation = '" &
window.form("txtInnovation").value & "', strFinancialPerformance = '" &
window.form("txtfinancialperformance").value & "'," _
& " dtLastUpdate = getdate(),
strLastUpdatedBy = '" & window.form("hdnLoginUserNTID").value & "'" _

& " WHERE intEntryID = " &
window.form("hdnEntryid").value & ""
' alert(strSQLupdate)
objConn.Execute(strSQLupdate)
objConn.Close()
'end if
end function
</script>
<script language=javascript>
function fnTestJs()
{
//if (event.clentY < 0)
//{
alert('hi');
// event.returnvalue = 'Close';
//}
}
</script>
<!-- <script for=window event=onunload>
alert(window.form("hdnEntryid").value);
//alert(window.event.clentY);
location.href="index.aspx"
</script> onunload="fnTest()"-->
</HEAD>
<body MS_POSITIONING="GridLayout" onunload="fnTest()">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top