Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 19th, 2009, 12:50 AM
Authorized User
 
Join Date: Jul 2007
Location: chennai, Tamilnadu, India.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default update database when browsr close

Sir,

I am using ASP 3.0 and SQL SERVER 2000 in my website. I want update logout time in my database when the browser close. If i wrote in the events Onunload or Onbeforeunload means it will fire refresh, back operations also but i need only the updation when the browser close .. Please give me a best solution for this problem

Thanking You
Reply With Quote
  #2 (permalink)  
Old March 19th, 2009, 06:24 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

There are some very good posts in this forum on giving yourself the best chance of doing this. I believe Imar is the persons replies you should look for. IMO Classic ASP fails in this area, at least I have never got this working personaly anyhow.... From memory you need to use a global.asa file and look at Session_OnEnd method - Given this method does not fire when the browser closes insteasd when the session ends it makes things difficult. I do recall Mr ASP (Imar) has a solution and has posted it.
__________________
Wind is your friend
Matt
Reply With Quote
  #3 (permalink)  
Old March 20th, 2009, 01:56 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
but i need only the updation when the browser close ..
You can't really determine the difference between a true browser close and navigating to the next page or a completely different web site. In all cases, the browser will fire this event.

So, as Mat pointed out, you probably want to do this server side in Session_OnEnd as that's the only way to detect a user has left and not requested a new page for some time.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #4 (permalink)  
Old March 22nd, 2009, 04:34 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Quote:
You can't really determine the difference between a true browser close and navigating to the next page or a completely different web site.
Not strictly true.

It's a pain, but you *CAN* make that determination.

Here is a very *SIMPLE* demonstration:
Code:
<script>
var goingAway = true; // assume the worst

function sayGoodbye( )
{
    if ( goingAway ) alert("Leaving so soon?  Sorry to see you go.");
}
</script>
<body onunload="sayGoodbye();">
<a href="www.google.com">visit google</a>

<form action="anotherPageOnThisSite.html" onsubmit="goingAway=false; return true;">
Give me your name: <input name="name">
<input type=submit value="Log in">
</form>
Do you see it?? You just need to make sure that EACH AND EVERY WAY that a person might navigate to another page on your site sets the goingAway flag to false and then the logic in ONUNLOAD (and it could be in ONBEFOREUNLOAD) can ignore those moves while capturing all others.

Now, it's still not perfect. The user can simply kill the browser (e.g., with the task manager) or could lose connection (modem goes dead) and you'll never *get* the unload event. So you still should have the backup of Session.OnEnd in global.asa or equivalent. But used with care you *can* capture the majority of all cases you need to catch.
Reply With Quote
  #5 (permalink)  
Old March 22nd, 2009, 06:58 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

mmmm I do like reading posts on this topic. Sorry in advance that my opinion is not a solution for your issue, a thought and my 2 cents worth:

Over the last few years every classic ASP coder in our office has gone to .NET however I have stuck with classic ASP. Is it because im the oldest and have been there the longest or is it because I think my job is secure.....Anyhow what ever the reason this issue is about the only thing I would like to offer clients which I have not been able to with confidence. The .NET guys can do this with confidence and remind me of it when ever they can (all in good spirits of course). I have now become very good at avoiding this dreaded deliverable when it rears its, In my opinion, its ugly head.
__________________
Wind is your friend
Matt
Reply With Quote
  #6 (permalink)  
Old March 23rd, 2009, 02:08 AM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Okay, I give up. How do the ASP.NET guys do this with any more confidence than you'd have with ASP???

I, for one, have never seen a .NET-based solution. That is, not one that differs from the JavaScript one I gave above.

There's no way for ASP.NET to prevent somebody from simply typing a new URL into his/her browser.

Enlighten us. Are your mates a heluva lot smarter than the ASP.NET world, in general???
Reply With Quote
  #7 (permalink)  
Old March 23rd, 2009, 07:07 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

About typing a new URL, im sure they dont have an answer for that one. In short they just remind me about the improved state management and other related tools.

Are they a 'heluva lot smarter' than guys like yourself, Imar, Doug (sorry about those other super helpful experts which dont come to mind at this moment) and co.... Not even close :o)
__________________
Wind is your friend
Matt
Reply With Quote
  #8 (permalink)  
Old March 23rd, 2009, 07:51 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Yeah, but there's not one of those advanced .NET tools you can't do yourself. Well, to be fair, many of them would require writing a component for ASP. Resizing images comes to mind immediately. But you could even do cookieless sessions in ASP if you really wanted to. I believe that the old Barnes & Noble (booksellers) site did so, when it was written in ASP years ago.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Browser close when screen saver close Rehanrana Pro VB 6 1 April 7th, 2008 03:09 AM
When should you close the database connection? Stickannn Pro PHP 0 September 13th, 2007 04:25 AM
Database update on window close hemal_301080 ASP.NET 1.0 and 1.1 Professional 1 August 12th, 2006 02:34 PM
Close Database using VBA Stanny Access VBA 4 May 31st, 2006 01:49 AM
How to close database opened by adodc aa_azadeh Pro VB Databases 1 September 28th, 2004 08:04 AM



All times are GMT -4. The time now is 04:49 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.