server needs to know when user closes browser window

Discussion in 'ASP .Net' started by feng, Dec 3, 2003.

  1. feng

    feng Guest

    Hi,

    When user closes a browser window by clicking on the "X"
    button, I want the server to be noticed (either through
    postback or calling other ASP pages, etc.) and perform
    some task accordingly. Please note that I can't use
    session end event, since the session is still alive now
    and the user is just closing a secondary window he/she
    opened.

    I tried to use the <BODY> tag's onunload client side event
    and put a flag in a hidden textbox then submit the form
    (post back). But this didn't work for me -- my code on the
    server side can't really capture the event properly.

    What's the proper way of doing this? Can anyone help me?

    Thanks
    feng, Dec 3, 2003
    #1
    1. Advertising

  2. OnUnload is an option, but you have to have a method of speaking to the
    server. Perhaps having the code navigate to another page that says "are you
    sure you want to close this window" and having that page tell you they are
    closing the window. But, that might tick off users.

    The difficulty here is HTTP is stateless, which means the client is
    disconnected once they have recieved a page. In an Intranet environment, you
    have more options, of course.

    If you can set up the popup window so there is no header bar (thus no X to
    close) and put a "Close window" button, you have the ability to handle the
    event on the server side, but this may end up causing a dialog stating
    "someone is trying to close this window" or similar.

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    **********************************************************************
    Think Outside the Box!
    **********************************************************************
    "feng" <> wrote in message
    news:073501c3b9b9$67831cc0$...
    > Hi,
    >
    > When user closes a browser window by clicking on the "X"
    > button, I want the server to be noticed (either through
    > postback or calling other ASP pages, etc.) and perform
    > some task accordingly. Please note that I can't use
    > session end event, since the session is still alive now
    > and the user is just closing a secondary window he/she
    > opened.
    >
    > I tried to use the <BODY> tag's onunload client side event
    > and put a flag in a hidden textbox then submit the form
    > (post back). But this didn't work for me -- my code on the
    > server side can't really capture the event properly.
    >
    > What's the proper way of doing this? Can anyone help me?
    >
    > Thanks
    Cowboy \(Gregory A. Beamer\), Dec 3, 2003
    #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. =B=
    Replies:
    3
    Views:
    3,840
  2. Charlie@NISH
    Replies:
    3
    Views:
    784
    Marina
    Aug 30, 2005
  3. Spammay Blockay
    Replies:
    1
    Views:
    402
    Dietmar Meier
    Feb 4, 2005
  4. Luke Matuszewski
    Replies:
    8
    Views:
    628
    Luke Matuszewski
    Dec 2, 2005
  5. karthi
    Replies:
    0
    Views:
    116
    karthi
    Jan 31, 2006
Loading...

Share This Page