Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Newbie Question on Page_Unload Event

Posted on 2004-05-02
2
Medium Priority
?
821 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

773 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