?
Solved

Newbie Question on Page_Unload Event

Posted on 2004-05-02
2
Medium Priority
?
817 Views
Last Modified: 2012-06-27
  I read something about asp.net's event handling. And I got the idea that the requested page's calling procedure like the following:
  1. Page_init
  2. Page_Load
  3. Page_Unload

    And the book said that page_unload is executing at the serverside
and executed after page_load event and before the page was sent to
the browser. So I try to use the Trace feature to debug the Page_Unload
event, but I cannot find the trace output for the Page_Unload event. Why?
Could you help me?

    In case you want to have a try, I list the sample asp.net file.

        <%@ Page Language="C#" Trace="true" %>
        <script runat="server">

            // Insert page code here
            //
            void Page_Load() {
            Trace.Write("Page Load here!");
            }

            void Page_Unload() {
            Trace.Write("Page Unload here!");
            }

        </script>
        <html>
        <head>
        </head>
        <body>
        Hello World
        </body>
        </html>

----------------------------------------------------------------------
Trace Information:
      aspx.page Begin Init
      aspx.page End Init 0.000047 0.000047
                      Page Load here! 0.000468 0.000421
      aspx.page Begin PreRender 0.000517 0.000048
      aspx.page End PreRender 0.000557 0.000041
      aspx.page Begin SaveViewState 0.000688 0.000131
      aspx.page End SaveViewState 0.000717 0.000029
      aspx.page Begin Render 0.000744 0.000027
      aspx.page End Render 0.000931 0.000187

-----------------------------------------------------------------------
I cannot find the Trace for "Page_Unload here!". Why ASP.net's trace don't trace the Page_Unload event?

Best Regards,
Yang

0
Comment
Question by:yasun_lucent
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
ggkumaresh earned 60 total points
ID: 10975101
Hi...

   The message added by the Page_Unload subroutine is never displayed because the Unload event occurs after any content has been rendered to the browser.

    so u can't get the message that u have typed in the unload event..


Regards;
Kumaresh

0
 
LVL 1

Assisted Solution

by:CouldNotFindAnyOtherUsername
CouldNotFindAnyOtherUsername earned 90 total points
ID: 10975307
Yes,  ggKumaresh is right, Page_Unload Subroutine is called after the Render Method has been called. So anything you do in Page_Unload will not be rendered, even the trace information.

What I know is that Page_Unload (Page.Unload) event is meant (if at all) for cleaning up the objects...


If you want to learn the order of Page Lifecycle visit the following MSDN article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcontrolexecutionlifecycle.asp


Infact, the above article clearly metions the following for the Page_Unload (Page.Unload) Event:
Perform any final cleanup before the control is torn down. Control authors generally perform cleanup in Dispose and do not handle this event.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question