Calling server-side function from client javascript

M

M B HONG 20

Hi all -

I am developing an ASP.NET (C#) application and need some help. I wish
to call a server-side function (in the code-behind "file.aspx.cs") upon
a user clicking on the "X" to close the browser window. Is there a way
to postback and call a server-side function when this happens? I am
aware of the browser's native "onunload" event, but am not certain that
what I'm looking for is actually possible. Any help would be greatly
appreciated, thanks in advance.
 
M

Martin Honnen

M B HONG 20 wrote:

I am developing an ASP.NET (C#) application and need some help. I wish
to call a server-side function (in the code-behind "file.aspx.cs") upon
a user clicking on the "X" to close the browser window. Is there a way
to postback and call a server-side function when this happens? I am
aware of the browser's native "onunload" event, but am not certain that
what I'm looking for is actually possible.

Traditionally the onunload handler has not been a reliable way to get
any communication done with the server. Some browsers (IE since IE 5,
Firefox, newer Mozillas) provide an onbeforeunload handler where you
might have more chances. But that handler brings up a dialog window
asking the browser user to confirm that he wants to navigate away. And
script in that handler cannot check what the user does in the dialog.
And both onunload and onbeforeunload are fired too when links are
followed, form submitted, new URLs loaded after being entered in the
location bar, you cannot precisely distinguish whether some tries to
close a browser window or navigates to a new URL.
 
T

Thomas 'PointedEars' Lahn

Martin said:
Traditionally the onunload handler has not been a reliable way to get
any communication done with the server.
True.

Some browsers (IE since IE 5, Firefox, newer Mozillas) provide an
onbeforeunload handler where you might have more chances. But that
handler brings up a dialog window asking the browser user to confirm
that he wants to navigate away.

AIUI only if a string is returned from the assigned event listener.

<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onbeforeunload.asp>
And script in that handler cannot check what the user does in the dialog.

Which would not be necessary if something else or nothing (== undefined)
is returned.
And both onunload and onbeforeunload are fired too when links are
followed, form submitted, new URLs loaded after being entered in the
location bar, you cannot precisely distinguish whether some tries to
close a browser window or navigates to a new URL.

True, however
<URL:http://www.faqts.com/knowledge_base/view.phtml/aid/7733/fid/53>


PointedEars
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top