Call a server side method at browser close in asp.net
Hi members
I am trying to find a way to catch browser close event and call a server side code for database entry .I have tried Javascript for window.onbeforeunload and body.onunload but unload event is fired everytime the page navigates i need to catch only browser close event.I am using asp.net with C# and my page have a master page.
Thanks in advance
Shakti
Re: Call a server side method at browser close in asp.net
Hey,
Have a look at the following article:
http://aspalliance.com/1294_CodeSnip...ServerSide.all
I believe it will help.
Gary
Re: Call a server side method at browser close in asp.net
That method won't work for these reasons:
1) It'll get called even if you click on a link and move to another page,
2) And it'll get called if you refresh the page.
2a) So for that reason a 'popular' workaround is to add this around the method call:
Code:
if((window.event.clientX<0) || (window.event.clientY<0))
{
...
}
3) However, it still won't get called if you have multiple tabs open and you close the browser window.
4) It will work if your userbase only uses the same browser and no other and doesn't open any other tabs.
My point? You've got a design flaw and you're trying to find a workaround, it's not addressing the real issue. What are you trying to update in the database?
Re: Call a server side method at browser close in asp.net
Hi
thanks for ur reply
I want to call a server side function to handle credit card processing.
I need only to catch browser close event and fire a server side code at the same time.
Bhupendra
Re: Call a server side method at browser close in asp.net
I dont have <body.....> tag because i am using master page and i am performing this on child page.
How i can use contentplaceholder with onbeforeunload event??
Re: Call a server side method at browser close in asp.net
Quote:
Originally Posted by
shakti5385
Hi
thanks for ur reply
I want to call a server side function to handle credit card processing.
I need only to catch browser close event and fire a server side code at the same time.
Bhupendra
Whoa there... then you shouldn't be doing this at all. You're doing credit card processing, no part of your processing logic should depend on this kind of functionality. As I mentioned before, there is no guarantee that the onunload/onbeforeunload will work in a browser. It may work in some, it won't work in all in all situations. You need to go back and change this, it's not good to take someone's credit card information and 'play' with it considering how fragile the proposed logic is.
Re: Call a server side method at browser close in asp.net
Can't agree with the above more.
You have to be very careful when dealing with this type of information, and to say that I would be concerned about using a site that implemented this type of logic would be an understatement.
Have you considered using a Credit Card Processing Gateway, rather then implementing your own logic?
Gary