Results 1 to 7 of 7

Thread: Call a server side method at browser close in asp.net

  1. #1

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    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

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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?

  4. #4

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    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

  5. #5

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    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??

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Call a server side method at browser close in asp.net

    Quote Originally Posted by shakti5385 View Post
    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.

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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
  •  



Click Here to Expand Forum to Full Width