Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: unload event for a aspx page

  1. #1
    keroed1 Guest

    Default unload event for a aspx page

    i wanted to know if i could let my aspx page execute a line of code everythime the page is closed ( for example if some click the exit button in the internet browser) i tried using the Page_Unload but it didn't work i am not sure if thats what i should be using or if i implemented correctly can someone help me please

  2. #2
    keroed1 Guest

    Default

    to be honest i am not even sure if this is practical or possible, is a friend trying to implement this in his website and i was trying to assist him

  3. #3
    Join Date
    Dec 2002
    Posts
    500
    Rep Power
    0

    Default

    you can set an event handler for window.onunload (client side script), and then do an XMLHTTPRequest.
    Cultured in Aggression and Koding like a Warrior!!
    “Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
    "The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein

  4. #4
    keroed1 Guest

    Default

    can u show me a code snippet how to do this please?

  5. #5
    TwistedPair Guest

    Default

    http://developer.mozilla.org/en/docs...indow.onunload
    <html>
    <head>

    <title>onunload test</title>

    <script type="text/javascript">

    window.onunload = unloadPage;

    function unloadPage()
    {
    alert("unload event detected!");
    }
    </script>
    </head>

    <body>
    <p>Reload a new page into the browser<br />
    to fire the unload event for this page.</p>
    <p>You can also use the back or forward buttons<br />
    to load a new page and fire this event.</p>
    </body>
    </html>
    Did a lil googling, the problem with this solution is that it does not only fire when the browser is being closed but I guess its a start.

  6. #6
    keroed1 Guest

    Default

    oh cool i tried that and it works but i jus realsied that i cant use javascript to update a value in a database. i was trying to whenever someone leaving the site i would capture the time the left the site and update it in the database

  7. #7
    TwistedPair Guest

    Default

    I believe you can track sessions natively in asp.net, I remember seeing an example where they used that fact to make a hit counter and to show the current amount of online users. Where every time a session times out you subtracted 1 every time a session is created you add 1.

  8. #8
    keroed1 Guest

    Default

    yes but in this case it wouldnt be a time out the person got timed out they prob jus left the website. thus in essense its the page unloading i want to capture that time and log it to a database.

  9. #9
    Join Date
    Jul 2006
    Posts
    239
    Rep Power
    0

    Default

    For a page unload you will need the following sub procedure

    [VB.Net]
    Private Sub Page_Unload(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Unload

    End Sub

  10. #10
    keroed1 Guest

    Default

    i am thinking of doing the following it seems a likkle bit sloppy at the moment going to still try a better way of doing it though

    <script type="text/javascript" FOR="window" EVENT="onunload">

    new_window = window.open('default.aspx','default', ' menubar,resizable,dependent,status, width=300,height=200,left=500,top=10')

    </script>

    1. they will still be able to be redirected to the website they entered or the window will still close if they clicked the exit button
    2. a new window wid open that jus displays a good bye message jus for sure and then within that i going to log the log out time and any other information i wanted to set in my database

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •