|
-
Dec 21st, 2009, 01:06 PM
#1
Thread Starter
Just Married
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
-
Dec 21st, 2009, 04:54 PM
#2
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
-
Dec 22nd, 2009, 08:43 AM
#3
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?
-
Dec 22nd, 2009, 04:05 PM
#4
Thread Starter
Just Married
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
-
Dec 22nd, 2009, 04:08 PM
#5
Thread Starter
Just Married
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??
-
Dec 22nd, 2009, 05:47 PM
#6
Re: Call a server side method at browser close in asp.net
 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.
-
Dec 23rd, 2009, 02:36 AM
#7
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|