473,700 Members | 2,553 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 5648
<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
6352
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
2259
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
9124
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
4918
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
5227
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
4040
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
1301
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
8713
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8639
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
7795
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...
1
6556
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4650
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2021
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.