473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Calling server-side function from client javascript

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.

Nov 29 '05 #1
2 5726


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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 29 '05 #2
Martin Honnen wrote:
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.


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>
<URL:https://bugzilla.mozilla.org/show_bug.cgi?id=68215>
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
Nov 29 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: bhennon | last post by:
Hey all, I have a small php script that calls a random image at the following page. http://www.2006ymcanationals.com/random.php IT WORKS IF I go directly to the above link. I am trying to...
6
by: dw | last post by:
Hello all, I'm having a dickens of a time calling a stored procedure on a connection. Every time I do, it generates an error "Arguments are of the wrong type, are out of acceptable range, or are in...
1
by: ZeBerg | last post by:
Is it possible to have a stored procedure in database A while calling it from database B and have it manipulate the tables in database B (whatever the calling database happens to be)? We have a...
8
by: Vinod | last post by:
Hi, I have a problem, i am calling an exe from asp program. Its not working fine. When i execute the exe through the dos program directly i get the desired result. My exe will convert files in...
3
by: Julia | last post by:
Hi, I have a windows application which create a singleton remote object And a net application which call the remote object both on the same machine(windows 2000,iis 5.0) here is the code...
1
by: Steve.Goodman | last post by:
Appologies if this has already been asked, but after scanning the web and this news group I could find no decent solution. We have a windows App that calls a webservice, using this bit of basic...
4
by: Jack | last post by:
Hi, I am trying to run an example code from a book. However I am getting the following error message: Number: -2147217900 Description: Syntax error or access violation Source: Microsoft OLE...
3
by: RvGrah | last post by:
If I use a Sql Server 2005 Express copy of a database on my local machine to develop my apps, can I then just substitute (Ctl+Shift + H "replace all") the server name of my local machine with the...
4
by: eighthman11 | last post by:
I'm calling a stored procedure on a sql server from an access application. I just need the stored procedure to run I do not need any data returned from the stored procedure to my Access...
2
by: ambujnema | last post by:
When I am calling C# dll into Vb6.0 through Server.CreateObject (“ClassLibrary1.Class1”). I stuck at one place; I have to pass some parameter in that class, Class contain two methods, in which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.