Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > When browser is closed i want to call the web method of the webservice .. How can be done.??

Reply
Thread Tools

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

 
 
Gouri.Mahajan7@gmail.com
Guest
Posts: n/a
 
      06-11-2008
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.
 
Reply With Quote
 
 
 
 
subtile
Guest
Posts: n/a
 
      06-11-2008
would it be possible with som javascript.. calling a webservice ?
--

Jesus Loves You


"Mark Rae [MVP]" wrote:

> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
> > 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
>
>

 
Reply With Quote
 
 
 
 
Michael Nemtsev [MVP]
Guest
Posts: n/a
 
      06-11-2008
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


s> would it be possible with som javascript.. calling a webservice ?
s>
s> "Mark Rae [MVP]" wrote:
s>
>> <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)
>> ...
>>
>>> 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.ne



 
Reply With Quote
 
Munna
Guest
Posts: n/a
 
      06-11-2008
On Jun 11, 7:53 pm, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> "subtile" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
> [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="somefunction()">
<form id="form1" runat="server">
</form>
</body>
<script language="javascript" 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
 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      06-11-2008
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]" <(E-Mail Removed)> wrote:
> > "subtile" <(E-Mail Removed)> wrote in message
> >
> > news:(E-Mail Removed)...
> >
> > [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="somefunction()">
> <form id="form1" runat="server">
> </form>
> </body>
> <script language="javascript" 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
>

 
Reply With Quote
 
Munna
Guest
Posts: n/a
 
      06-11-2008
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


 
Reply With Quote
 
Munna
Guest
Posts: n/a
 
      06-11-2008
Hi

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

the event onbeforeunload will fire each and every time browser
navigate,postback,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="somefunction()">
<form id="form1" runat="server">
</form>
</body>
<script language="javascript" 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
 
Reply With Quote
 
Munna
Guest
Posts: n/a
 
      06-11-2008
On Jun 11, 9:47 pm, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> "Munna" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
> > when mouse down in browser document traked it down.

>
> Alt-{F4}
> Alt F X
> Alt-{LEFT} / Alt-{RIGHT}
> Ctrl-{F5}
>
> Etc...
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net


Hi

Nice points by Mark...

well here is a simple javascript function that can be used to handle
key events...

this is just an example...

<body onbeforeunload="doUnload()" onmousedown="somefunction()">
<form id="form1" runat="server">
</form>
</body>
<script language="javascript" type="text/javascript">
var isClose = false;

//this code will handle the F5 or Ctrl+F5 key
document.onkeydown = checkKeycode
function checkKeycode(e) {
var keycode;
if (window.event)
keycode = window.event.keyCode;
else if (e)
keycode = e.which;

if(keycode == 116)
{
isClose = true;
}
}

function somefunction()
{
isClose = true;
}

function doUnload()
{
if(!isClose)
{
alert('window is closing');
}
}
</script>


Thanks

Munna
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Asynchronous Call of WebService method within a WebService RenÚ Preu▀ler ASP .Net Web Services 0 10-29-2008 11:55 AM
Webservice He!p - Response error: "An existing connection was forcibly closed by the remote host" even when no error in web method iKiLL ASP .Net Web Services 0 12-20-2006 04:14 PM
Webservice He!p - Response error: "An existing connection was forcibly closed by the remote host" even when no error in web method iKiLL ASP .Net 0 12-20-2006 04:14 PM
Long call to webservice generates "underlying connection was closed: An unexpected error occurred on a receive."Error Techsatish ASP .Net Web Services 1 09-22-2006 03:18 AM



Advertisments