window close event

Discussion in 'ASP .Net' started by Murtaza Iqbal Gandhi, Apr 19, 2009.

  1. i am looking for a strategy by which i can detect a client going
    offline, asynchronously.

    i don't want to wait for the session to expire.
    Murtaza Iqbal Gandhi, Apr 19, 2009
    #1
    1. Advertising

  2. www.ghoz.net | wrote:
    > First of all, create a new ASP.NET page in your favorite IDE and add an
    > instance of the ScriptManager to it. Make sure you configure the
    > ScriptManager to enable Page Methods.
    >
    > Listing 1
    >
    > <asp:scriptmanager id="ScriptManager1" runat="server"
    > enablepagemethods="true" />Next, we will subscribe to the unload event
    > of the body tag of the ASP.NET page and assign a callback method to be
    > called when this event fires.
    >
    > Listing 2
    >
    > <body onunload="HandleClose()">The HandleClose function is placed within
    > the Head section of the page.
    >
    > Listing 3
    >
    > <script language="javascript" type="text/javascript">
    > //<![CDATA[
    > function HandleClose() {
    > alert("Killing the session on the server!!");
    > PageMethods.AbandonSession();
    > }
    > //]]>
    > </script>As you can see, the function shows an alert message box
    > informing the user that the session will be killed on the server side.
    > Then it makes a call to the AbandonSession server side method that is a
    > Script-enabled method. For more information about the Page Methods in
    > AJAX 1.0, make sure you check the AJAX documentation.
    >
    > On the server side, all that you have to do is define the AbandonSession
    > method and add to it the WebMethod attribute.
    >
    > Listing 4
    >
    > [WebMethod]
    > public static void AbandonSession()
    > {
    > HttpContext.Current.Session.Abandon();
    > }The above line of code makes sure that the session is now cleared and
    > causes the Session_End event, which is defined inside the Global.asax to
    > fire.
    >
    > Inside the Global.asax you can place any code you want to execute when
    > the session ends.
    >
    > That is all what you have to do to run any server side code when the
    > browser is closed by the user!
    >
    > Hope this snippet is helpful and that you have enjoyed it!!
    >
    > Source:
    > http://aspalliance.com/1294_CodeSnip_Handle_Browser_Close_Event_on_the_ServerSide.3
    >
    > Mahmoud Ghoz
    > www.Ghoz.NET
    >
    >> i am looking for a strategy by which i can detect a client going
    >> offline, asynchronously.
    >>
    >> i don't want to wait for the session to expire.
    >>

    >
    >

    thanks.
    i would check that ...
    Murtaza Iqbal Gandhi, Apr 19, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    6
    Views:
    8,832
    sateeshranga
    Aug 7, 2008
  2. Iñaki Baz Castillo
    Replies:
    7
    Views:
    849
    Iñaki Baz Castillo
    Jan 12, 2010
  3. Walter Beierdonck

    Self.close() window without the dialog close?Yes/NO

    Walter Beierdonck, Apr 29, 2004, in forum: Javascript
    Replies:
    1
    Views:
    343
    Grant Wagner
    Apr 30, 2004
  4. Replies:
    3
    Views:
    405
    Chung Leong
    Jan 16, 2005
  5. Shang Wenbin

    close current window using window.close()

    Shang Wenbin, Sep 1, 2005, in forum: Javascript
    Replies:
    10
    Views:
    370
    Gérard Talbot
    Sep 2, 2005
Loading...

Share This Page