Detect if browser closed

P

Patrice

If this is during a request try IsClientConnected.

Else you have to callback the server when it happens (and in the case of a
client side crash or if JS is disabled etc..., you'll never know the browser
closed).

Generally I try to design for not having to care... (you may want to explain
what you want to do when the user closes the browser).

Patrice
 
S

Sambathraj

Hi,
If Javascript is enabled in the client side, then you can use window.Closed
property to check whether the window is close.
For eg in Child window to check the parent window is closed you can use
if(window.parent.closed)
// do some thing

Regards,
Sambathraj
 
C

Chris

Ok what needs to have happen.
when a user edits a record I am locking the record by a bit field.
So if the user clicks the x on that edit screen I need detect that and
unlock the record in the database.

I am storing the locking by user session.sessionID.
If you know of a way to get all session.sessionID's that would work for me
too. I can run a check on that instead. Which is what I want to do.

Thanks
 
K

Kevin Spencer

Hi Chris,

You can't tell when the browser has closed, as HTTP is stateless. That is
why Sessions time out, and why there is a Session_End event handler in your
global class. Assuming that your app can wait 20 minutes to perform this
cleanup task, that's the place to do it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
P

Patrice

Are you sure you need exclusive locking ? Did you checked the optimistic
approach ? What is the probability to have multiple people editing the same
record at the same time ?
You could also keep a datetime instead of just a bit field. It would allow
to have a safety mecanism so that a long running lock could be discarded...

If you really need you could trap onbeforeunload or onclose or a similar
client side event to call a server side page to unlock the record.

Patrice

--
 
C

Chris

Well I have gone another route. Just to let you all know.
First off thanks for the info

I am now using the system.web.cacheing.cache
I store a dataset in there with a recordid and a recordtype

now if the user closes his brower it will take about 5 mins for the
application to unlock that record in the cache.
 

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,053
Latest member
BrodieSola

Latest Threads

Top