473,387 Members | 1,890 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,387 software developers and data experts.

Page Close Event In ASP.NET??

IS There An EventHandler or Script To Catch When The Page Is Closing(similar to the Closing event in WInforms)

Thanks
Nov 18 '05 #1
4 6234
Hello =?Utf-8?B?VmlubnkgVmlubg==?=,

Depending on what you're trying to do... If you're trying to catch the browser window closing, then you'll need to do that via client side javascript (<body onUnload="someMethod()"/>

If you want to trap when the page gets unloaded on the server side (ie: after it's sent to the browser, your event is Page.Unload.
IS There An EventHandler or Script To Catch When The Page Is
Closing(similar to the Closing event in WInforms)?

Thanks

--

--
Matt Berther
http://www.mattberther.com
Nov 18 '05 #2
If the user closes out the browser without something posting that data back
to the server, then you're out of luck.
However, if you keep track of what the user's doing, and place that data
somewhere in their session, or in a databade, then you could do something
when the user's session ends. (a result of them closing out the browser).

If you're working with IE only, then I guess you could create a client-side
javascript function that created an xmlhttp (ActiveX) object and posted the
form's information to the server as an XML document (where this function
executes on the page's onUnload Event). But that also means the function
would run every time the page posts back too. To get around this, you could
check the event's X,Y coordinates to see if it happened inside of the window
(is it happened at a negative Y coordinate, then the user clicked "x")

These are just sone random musings...Hope they help
"Vinny Vinn" <an*******@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com...
I apologize for not be clear as to what i am trying to do.

When the page is x out (not Redirected) i would like to save (to a database) any data that the user entered.

Nov 18 '05 #3
David
Thanks for your suggestions
How would i get the x,y coordinates from the unload event?
Nov 18 '05 #4
Hello David,

I've recently done something quite similar to this. However, I set up a web service that would accept the data to write it into the database.

The client browser had <body onUnload="saveData();">, with a reference to a javascript file that defined the saveData method.

This method was responsible for generating the SOAP envelope and using the XMLHTTP object to submit this to the web service.

A fairly clean implementation, if I do say so myself, given that we were targeting only IE5+.
If you're working with IE only, then I guess you could create a
client-side javascript function that created an xmlhttp (ActiveX)
object and posted the form's information to the server as an XML
document (where this function executes on the page's onUnload Event).
But that also means the function would run every time the page posts
back too. To get around this, you could check the event's X,Y
coordinates to see if it happened inside of the window (is it happened
at a negative Y coordinate, then the user clicked "x")


--
Matt Berther
http://www.mattberther.com
Nov 18 '05 #5

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

Similar topics

4
by: Fabrizio | last post by:
I've this problem. I need, when the user close the web page, to show a message of confirm with Ok and cancel. With the event unload when I click cancel the web page closes however. What can I do...
4
by: KS | last post by:
Is it possible to write a javascript that makes a popup window when someone click on buttons/href on my page and close itself when the new page is about to get loaded? I want to prevent the user...
4
by: Vincent Yang | last post by:
I'm using Access 2002. My database is in Access 2000 format. I'm designing a form to collect responses to a 40-item questionnaire. I can fit four list boxes on a screen, so I plan to have 11 tab...
1
by: JezB | last post by:
1) How can I force page closure from server side c# code ? (eg. on my own Close button event). 2) I want to do some session variable cleanup when the user is finished with my page. Where is the...
9
by: Daniel Walzenbach | last post by:
Hi I am faced with the following problem: I have a page (let’s call this page page1.aspx) containing some TextBoxes and a hyperlink which opens another page (let’s call this page page2.aspx)...
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
1
by: =?Utf-8?B?Q2hyaXNB?= | last post by:
Two questions: 1. I have several asp.net pages that initiate a file download, via Response.WriteFile(). This works fine, except that it leaves the original page up. These pages are generally...
9
by: Bali | last post by:
Default.aspx is the starting page containing a control(ascx) which has asp:button control on it. On the button click event it has to open a new page as a modal control. Since refreshing a page in a...
0
by: Bali | last post by:
Default.aspx is the starting page containing a control(ascx) which has asp:button control on it. On the button click event it has to open a new page as a modal control. Since refreshing a page in...
5
by: =?Utf-8?B?U3RldmVuIFRhbmc=?= | last post by:
It seems that one page XBAP whose Unloaded event never get called, I need put some clearing stuff (I.G stop dispatcher time) when user close browser, it unload event doesn't work, where shall I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.