Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. invoke a severside code when clicking browser close buton

invoke a severside code when clicking browser close buton

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netsysadminquestion
14 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vipin d
    wrote on last edited by
    #1

    hi , i am using asp.net2003 with c# i need to know how we can invoke a server side function when user click browser close button???

    All I ever wanted is what others have....
    CrazySanker

    C N 2 Replies Last reply
    0
    • V Vipin d

      hi , i am using asp.net2003 with c# i need to know how we can invoke a server side function when user click browser close button???

      All I ever wanted is what others have....
      CrazySanker

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You can't.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      1 Reply Last reply
      0
      • V Vipin d

        hi , i am using asp.net2003 with c# i need to know how we can invoke a server side function when user click browser close button???

        All I ever wanted is what others have....
        CrazySanker

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        Handle the Javascript event and call an AJAX method.


        only two letters away from being an asset

        V 1 Reply Last reply
        0
        • N Not Active

          Handle the Javascript event and call an AJAX method.


          only two letters away from being an asset

          V Offline
          V Offline
          Vipin d
          wrote on last edited by
          #4

          is it possible to use AJAX in asp.net 2003 i think we can use page's unload event... plz tell me some sample site to use ajax in asp.net 2003?..

          All I ever wanted is what others have....
          CrazySanker

          N B 2 Replies Last reply
          0
          • V Vipin d

            is it possible to use AJAX in asp.net 2003 i think we can use page's unload event... plz tell me some sample site to use ajax in asp.net 2003?..

            All I ever wanted is what others have....
            CrazySanker

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            AJAX type techiques have been around since about 1997, they have only recently been named AJAX and come into vogue. It makes use of XMLHttpRequest which is independent from any version ASP.NET.


            only two letters away from being an asset

            G 1 Reply Last reply
            0
            • N Not Active

              AJAX type techiques have been around since about 1997, they have only recently been named AJAX and come into vogue. It makes use of XMLHttpRequest which is independent from any version ASP.NET.


              only two letters away from being an asset

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              Mark Nischalke wrote:

              AJAX type techiques have been around since about 1997, they have only recently been named AJAX and come into vogue. It makes use of XMLHttpRequest which is independent from any version ASP.NET.

              And even before that similar techniques were used with hidden frames, minimal iframes and small image tags. :)

              --- single minded; short sighted; long gone;

              N 1 Reply Last reply
              0
              • G Guffa

                Mark Nischalke wrote:

                AJAX type techiques have been around since about 1997, they have only recently been named AJAX and come into vogue. It makes use of XMLHttpRequest which is independent from any version ASP.NET.

                And even before that similar techniques were used with hidden frames, minimal iframes and small image tags. :)

                --- single minded; short sighted; long gone;

                N Offline
                N Offline
                Not Active
                wrote on last edited by
                #7

                I've tried to suppress those memories ;P


                only two letters away from being an asset

                1 Reply Last reply
                0
                • V Vipin d

                  is it possible to use AJAX in asp.net 2003 i think we can use page's unload event... plz tell me some sample site to use ajax in asp.net 2003?..

                  All I ever wanted is what others have....
                  CrazySanker

                  B Offline
                  B Offline
                  badgrs
                  wrote on last edited by
                  #8

                  Ajax is simply a technique that you achieve using Javascript. For what you want you'd need to hook into the body's onunload event and fire a quick request to the server. Of course there is no guarantee that this will ever run, and I'm pretty sure the browser close event is one situation that it won't. Best not to rely on it.

                  N 1 Reply Last reply
                  0
                  • B badgrs

                    Ajax is simply a technique that you achieve using Javascript. For what you want you'd need to hook into the body's onunload event and fire a quick request to the server. Of course there is no guarantee that this will ever run, and I'm pretty sure the browser close event is one situation that it won't. Best not to rely on it.

                    N Offline
                    N Offline
                    Not Active
                    wrote on last edited by
                    #9

                    badgrs wrote:

                    Of course there is no guarantee that this will ever run, and I'm pretty sure the browser close event is one situation that it won't.

                    Please, elaborate on this. Why would the call never run?


                    only two letters away from being an asset

                    G B 2 Replies Last reply
                    0
                    • N Not Active

                      badgrs wrote:

                      Of course there is no guarantee that this will ever run, and I'm pretty sure the browser close event is one situation that it won't.

                      Please, elaborate on this. Why would the call never run?


                      only two letters away from being an asset

                      G Offline
                      G Offline
                      Guffa
                      wrote on last edited by
                      #10

                      Basically because the page where code is running is already closing. You can hardly do anything there without opening a new window.

                      --- single minded; short sighted; long gone;

                      N 1 Reply Last reply
                      0
                      • G Guffa

                        Basically because the page where code is running is already closing. You can hardly do anything there without opening a new window.

                        --- single minded; short sighted; long gone;

                        N Offline
                        N Offline
                        Not Active
                        wrote on last edited by
                        #11

                        Strange. I have a project now were I'm calling an ajax method from the onunload script event and it seems to be working fine.


                        only two letters away from being an asset

                        1 Reply Last reply
                        0
                        • N Not Active

                          badgrs wrote:

                          Of course there is no guarantee that this will ever run, and I'm pretty sure the browser close event is one situation that it won't.

                          Please, elaborate on this. Why would the call never run?


                          only two letters away from being an asset

                          B Offline
                          B Offline
                          badgrs
                          wrote on last edited by
                          #12

                          I'll have to go back on what I said as closing the browser will run the code, but there are lots of cases where it won't. For instance, using the browsers back and forward buttons don't cause unload events (so if a user goes back a few pages before closing it won't run.....I don't think....), if the user has disconnected from tinternet, if the browser crashes, if you force quit the browser... It also depends on the browser, certainly IE has different ideas about when to call load events than Firefox. I'm not saying you can't use this method I'm just pointing out that it can't be 100% relied on (as anything client-side can't be)

                          N 1 Reply Last reply
                          0
                          • B badgrs

                            I'll have to go back on what I said as closing the browser will run the code, but there are lots of cases where it won't. For instance, using the browsers back and forward buttons don't cause unload events (so if a user goes back a few pages before closing it won't run.....I don't think....), if the user has disconnected from tinternet, if the browser crashes, if you force quit the browser... It also depends on the browser, certainly IE has different ideas about when to call load events than Firefox. I'm not saying you can't use this method I'm just pointing out that it can't be 100% relied on (as anything client-side can't be)

                            N Offline
                            N Offline
                            Not Active
                            wrote on last edited by
                            #13

                            badgrs wrote:

                            using the browsers back and forward buttons don't cause unload events

                            Yes, the event is fired.

                            badgrs wrote:

                            if the user has disconnected from tinternet, if the browser crashes, if you force quit the browser

                            Well of course you can't call a server-side method in this case :rolleyes:

                            badgrs wrote:

                            certainly IE has different ideas about when to call load events than Firefox.

                            As with many other things. Properly coding the application to handle different browsers is necessary in any professional, robust web application.


                            only two letters away from being an asset

                            B 1 Reply Last reply
                            0
                            • N Not Active

                              badgrs wrote:

                              using the browsers back and forward buttons don't cause unload events

                              Yes, the event is fired.

                              badgrs wrote:

                              if the user has disconnected from tinternet, if the browser crashes, if you force quit the browser

                              Well of course you can't call a server-side method in this case :rolleyes:

                              badgrs wrote:

                              certainly IE has different ideas about when to call load events than Firefox.

                              As with many other things. Properly coding the application to handle different browsers is necessary in any professional, robust web application.


                              only two letters away from being an asset

                              B Offline
                              B Offline
                              badgrs
                              wrote on last edited by
                              #14

                              Since your so adamant about it I had a little play around and I'm going to have to eat my words and say I'm wrong :-O I guess I didn't really give it much thought in the first place, just wanted to point out to the OP that javascript can't be relied upon....it seems we both know all about that though so no point in arguing technicalities.

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups