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. I want to catch event when user close page.

I want to catch event when user close page.

Scheduled Pinned Locked Moved ASP.NET
question
4 Posts 2 Posters 0 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.
  • B Offline
    B Offline
    buffering83
    wrote on last edited by
    #1

    I want to catch event when user close page. And i expect to work just one time. So i Write blow but it does work when page load. How can i catch event? protected void Page_UnLoad(object sender, EventArgs e) { }

    hi My english is a little. anyway, nice to meet you~~ and give me your advice anytime~

    A 1 Reply Last reply
    0
    • B buffering83

      I want to catch event when user close page. And i expect to work just one time. So i Write blow but it does work when page load. How can i catch event? protected void Page_UnLoad(object sender, EventArgs e) { }

      hi My english is a little. anyway, nice to meet you~~ and give me your advice anytime~

      A Offline
      A Offline
      Anuj Banka
      wrote on last edited by
      #2

      you can use this to catch close event for the page using this. < body onbeforeunload="alert('Closing');">

      B 1 Reply Last reply
      0
      • A Anuj Banka

        you can use this to catch close event for the page using this. < body onbeforeunload="alert('Closing');">

        B Offline
        B Offline
        buffering83
        wrote on last edited by
        #3

        Function < body önbeforeunload="alert('Closing');"> is also working when I click other button(which make refresh page). I want to execute .cs fuction when user close page or move other page. Thank you!

        hi My english is a little. anyway, nice to meet you~~ and give me your advice anytime~

        A 1 Reply Last reply
        0
        • B buffering83

          Function < body önbeforeunload="alert('Closing');"> is also working when I click other button(which make refresh page). I want to execute .cs fuction when user close page or move other page. Thank you!

          hi My english is a little. anyway, nice to meet you~~ and give me your advice anytime~

          A Offline
          A Offline
          Anuj Banka
          wrote on last edited by
          #4

          With the help of Jquery you can call code behind function somthing like this HTML Part: <script src="jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> function confirmSubmit() { $.ajax({ url: '/WebSite2/Default.aspx/SecretFormula', type: 'POST', contentType: 'application/json', data: '{}', success: function(result) { alert(result.d); } }); alert("I am in "); } </script> </head> <body onbeforeunload="confirmSubmit()"> <form id="form1" runat="server">

          </form> </body> </html> Code Behind Function:

          ** _**

          Public Shared Function SecretFormula() As Integer Return 42 End Function

          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