Browser close event

Discussion in 'ASP .Net' started by =?Utf-8?B?VmFtJHk=?=, Feb 24, 2006.

  1. 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()">
     
    =?Utf-8?B?VmFtJHk=?=, Feb 24, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sm mehta

    how to detect Browser close event.

    sm mehta, Jul 29, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    5,176
    Steve C. Orr, MCSD
    Jul 29, 2003
  2. Denon
    Replies:
    3
    Views:
    10,148
    Ed Crowley
    Nov 7, 2003
  3. Denon
    Replies:
    1
    Views:
    579
    Saravana [MVP]
    Nov 14, 2003
  4. Iñaki Baz Castillo
    Replies:
    7
    Views:
    860
    Iñaki Baz Castillo
    Jan 12, 2010
  5. Replies:
    0
    Views:
    500
Loading...

Share This Page