Click to See Complete Forum and Search --> : Page _Unload Event


aquafin
January 26th, 2006, 08:42 PM
When the user clicks on the close button of the web form(the (x) button on the tope right corner ) , I need to perform some operations,

So where do i write this functionality ?

I have wriiten the code in the page _unload event and page_disposed evnt , but it doesn't work ,

I have also tried with the application end and session end of the global.asax file, but it isn't working


Could anyone help me pls? :(

ITGURU
January 27th, 2006, 12:54 AM
Dear aquafin,

You can achieve this functionality as per following steps:
1. Add a method on onbeforeunload event of Body Tag of your ASPX page in Javascript.

2. In the method of onbeforeunload open a new web page as dialog window using showModalDialog method of the Window Class in Java script.

3. In web page which is loaded through showModalDialog method of window class, write all your code which you need to do when user close the web page using IE Close button (X) and after completing all the operation close your web form like as follows:

// Below code should be written in Code Behind file after completing all your operation.
// Generating final java script to be execute so that
// selected code and description value to be send back to calling page and
// also close down current PopUp window
lstrCommand = "<script>window.close();</script>";

// Executing java script created in previous step
Response.Write(lstrCommand);

Hope this will solve your problem.

aquafin
February 8th, 2006, 11:25 PM
That's a Good Idea,

Thanks ,