Solved

Newbie Question on Page_Unload Event

Posted on 2004-05-02
2
812 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

623 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