473,883 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When browser is closed i want to call the web method of the webservice .. How can be done.??

Hello,

Can anybody please tell me how to trap the browser close event. when
that is fired I want to call the web method.

Thanks in advance.

Regards,
Gouri.
Jun 27 '08 #1
13 5667
<Go************ @gmail.comwrote in message
news:ff******** *************** ***********@w8g 2000prd.googleg roups.com...
Can anybody please tell me how to trap the browser close event. when
that is fired I want to call the web method.
This is a fairly common question in this newsgroup.

Unfortunately, there is no reliable way to do this, because there is no
permanent connection between the webserver and the client browser. The
webserver has no idea what happens on the client browser until / unless it
receives another HttpRequest.

No doubt you'll receive other replies suggesting possible solutions with the
unload and/or beforeunload events - none of those works reliably...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #2
would it be possible with som javascript.. calling a webservice ?
--

Jesus Loves You
"Mark Rae [MVP]" wrote:
<Go************ @gmail.comwrote in message
news:ff******** *************** ***********@w8g 2000prd.googleg roups.com...
Can anybody please tell me how to trap the browser close event. when
that is fired I want to call the web method.

This is a fairly common question in this newsgroup.

Unfortunately, there is no reliable way to do this, because there is no
permanent connection between the webserver and the client browser. The
webserver has no idea what happens on the client browser until / unless it
receives another HttpRequest.

No doubt you'll receive other replies suggesting possible solutions with the
unload and/or beforeunload events - none of those works reliably...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #3
Hello subtile,

Yep, you can use onbeforeunload of the body < body onbeforeunload= "BrowerClose(); ">
and make ajax call to the web-service http://www.asp.net/ajax/documentatio...XTutorial.aspx

it's a common practice for this

---
WBR,
Michael Nemtsev [Microsoft MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
swould it be possible with som javascript.. calling a webservice ?
s>
s"Mark Rae [MVP]" wrote:
s>
><Go*********** *@gmail.comwrot e in message
news:ff******* *************** ************@w8 g2000prd.google groups.com
...
>>Can anybody please tell me how to trap the browser close event. when
that is fired I want to call the web method.
This is a fairly common question in this newsgroup.

Unfortunatel y, there is no reliable way to do this, because there is
no permanent connection between the webserver and the client browser.
The webserver has no idea what happens on the client browser until /
unless it receives another HttpRequest.

No doubt you'll receive other replies suggesting possible solutions
with the unload and/or beforeunload events - none of those works
reliably...

--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #4
"Michael Nemtsev [MVP]" <ne*****@msn.co mwrote in message
news:90******** *************** ***@msnews.micr osoft.com...
>>No doubt you'll receive other replies suggesting possible solutions
with the unload and/or beforeunload events - none of those works
reliably...
Yep, you can use onbeforeunload of the body < body
onbeforeunload= "BrowerClose(); "and make ajax call to the web-service
http://www.asp.net/ajax/documentatio...XTutorial.aspx
No you can't. That will fire every time the page closes i.e. moving from one
page to another, not just when the browser closes...
it's a common practice for this
No it isn't - because it doesn't work...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #5
"subtile" <su*****@discus sions.microsoft .comwrote in message
news:2D******** *************** ***********@mic rosoft.com...

[top-posting corrected]
would it be possible with som javascript.. calling a webservice ?
Not reliably... The JavaScript would fire every time the page closes i.e.
while moving from page to page within the same web app, and also during
postback etc...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #6
On Jun 11, 7:53 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
"subtile" <subt...@discus sions.microsoft .comwrote in message

news:2D******** *************** ***********@mic rosoft.com...

[top-posting corrected]
would it be possible with som javascript.. calling a webservice ?

Not reliably... The JavaScript would fire every time the page closes i.e.
while moving from page to page within the same web app, and also during
postback etc...

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
Hi,

what Mark is said is absolutely true and i found a little workaround
to that...

here is the code i tried and found working on both IE and Firefox...

<body onbeforeunload= "doUnload() " onmousedown="so mefunction()">
<form id="form1" runat="server">
</form>
</body>
<script language="javas cript" type="text/javascript">
var isClose = false;
function somefunction()
{
isClose = true;
}
function doUnload()
{
if(!isClose)
{
alert('window is closing');
}
}
</script>

this code is not perfect ... you guys can find some flaw ... still it
works... for most of the cases...

Best of luck

Munna

www.munna.shatkotha.com
www.munna.shatkotha.com/blog
Jun 27 '08 #7
this code fires on every page navigation (event postback) not just browser
close (though it will also fire on browser close).

this pattern is usually used to detect navigating away with unsaved data.
-- bruce (sqlwork.com)
"Munna" wrote:
On Jun 11, 7:53 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
"subtile" <subt...@discus sions.microsoft .comwrote in message

news:2D******** *************** ***********@mic rosoft.com...

[top-posting corrected]
would it be possible with som javascript.. calling a webservice ?
Not reliably... The JavaScript would fire every time the page closes i.e.
while moving from page to page within the same web app, and also during
postback etc...

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net

Hi,

what Mark is said is absolutely true and i found a little workaround
to that...

here is the code i tried and found working on both IE and Firefox...

<body onbeforeunload= "doUnload() " onmousedown="so mefunction()">
<form id="form1" runat="server">
</form>
</body>
<script language="javas cript" type="text/javascript">
var isClose = false;
function somefunction()
{
isClose = true;
}
function doUnload()
{
if(!isClose)
{
alert('window is closing');
}
}
</script>

this code is not perfect ... you guys can find some flaw ... still it
works... for most of the cases...

Best of luck

Munna

www.munna.shatkotha.com
www.munna.shatkotha.com/blog
Jun 27 '08 #8
Hi bruce

Thanks for your reply i checked the code again after your replay

did you actually run the code i suggesed...?

i tested this code and found working...

the trick is simple

when mouse down in browser document traked it down.

Thanks

Munna
Jun 27 '08 #9
Hi

well may be the code need a little explanation...

the event onbeforeunload will fire each and every time browser
navigate,postba ck,close...
as bruce said is right...

but i have subscribed another code that is mousedown of the body...

each time the user do a operation using mouse in the document i
tracked it down in a variable

if a use close its browser there is no mouse down in document... thats
why i used this code...

<body onbeforeunload= "doUnload() " onmousedown="so mefunction()">
<form id="form1" runat="server">
</form>
</body>
<script language="javas cript" type="text/javascript">
var isClose = false;
function somefunction()
{
isClose = true;
}
function doUnload()
{
if(!isClose)
{
alert('window is closing');
}
}
</script>

we can enhance this code ofcourse...
adding key press event to track down alt+f4 and etc...
Thanks

Munna
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
6372
by: James Marshall | last post by:
I'm writing a library where I want to override document.write(), but for all document objects; thus, I want to put it in the prototype. I tried Document.prototype.write= my_doc_write ; but it didn't work. I discovered that this seemed to work: HTMLDocument.prototype.write= my_doc_write ; Why does HTMLDocument work here but not Document? Will this second
2
2267
by: NWx | last post by:
Hi, I have the following question: I have an app that uses user login/logout to identify users When user logon, I register logon time in a session variable When user logoff using the logout link, I also register logoff time and update accordingly the logging history table. However user can simply close the browser without logoff, so his session was closed.
5
9135
by: news.microsoft.com | last post by:
Hi everyone, I need some help (may be in the form of some sample code) for the subject question. I have an ASP.NET/C# application. I need to do quite a few tasks when the session ends. I don't want to depend on the session timeout factor since it may end too soon or it may hang around too long. I can't find any event that fires when the browser closes. The Session_End event handler in the Global.asax does not execute until the...
9
4931
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work fine from a link. The button does bring up the popup window, but when I press the links on the page, it doesn't return or close the window. ****************************************************************************
7
5234
by: Boni | last post by:
Dear all, if I do myform.close() is it disposed or not? is it correct do following? myForm.close() Info=SomeControlOntheForm.text This seems to work. But am not sure that it is waterproof. Thanks, Boni
5
4055
by: Homa | last post by:
Hi all, Can anyone give me some links about how to do an async web service call from aspx and display a temperary page before the web service returns? Thanks, Homa Wong
0
1313
by: Matthew B. Lehrman | last post by:
I've googled all over the place trying to get answer to this question and some things have come close, but nothing quite. Asp.NET 1.1, Visual Studio 2003 I am writing Visual Basic apps. I can create a windows form that can consume and use the webservice. I can also access the webservice through my browser. But when I create an Asp.NET Web Application and try to consume the webservice, I am able to add the web reference, but when I call any...
0
9792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11141
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10415
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9573
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5991
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4220
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3232
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.