Solved

Newbie Question on Page_Unload Event

Posted on 2004-05-02
2
792 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
2 Comments
 
LVL 2

Accepted Solution

by:
ggkumaresh earned 20 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 30 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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