Solved

Newbie Question on Page_Unload Event

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now