Page_Unload... always

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Page_Unload... always

    Hi.

    Debugging one of my pages I noticed that everytime I call the page,
    the first event to run is Page_Load and after it the Page_Unload. If I
    postback to the page the Page_Unload runs again. Shouldn't the
    Page_Unload event runs only when I close the page or submit the page?
    I can't understand why the Unload event runs when I load the page !!

    Thanks,

    Robert Scheer
    Robert Scheer Guest

  2. #2

    Default Re: Page_Unload... always

    Page_Unload event happens server-side and has nothing to do with closing the
    page. Page lifecycle is as follows per request:

    1. Instantiate
    2. Initialize
    3. TrackViewState
    4. LoadViewState (postback)
    5. Load postback data (postback, IPostBackDatahandler.LoadPostdata)
    6. Load
    7. Load postback data for dynamical controls added on Page_Load
    8. Raise Changed Events (postback,
    IPostBackDatahandler.RaisePostDataChanged)
    9. Raise postback event (postback, IPostBackEventHandler.RaisePostBackEvent)
    10.PreRender
    11. SaveViewState
    12. Render
    13. Unload
    14. Dispose

    As you can see Unload phase happens as 13th on the list. Important is that
    these sequences happen on every request. Those that have (postback) happen
    only on postbacks, but Page_Unload happens on every request. Here the Page
    performs cleanup.

    Reason is that Page class is created on every request to serve requests and
    for example inital request and postbacks are actually server by different
    class instances. Therefore Page_Unload happens on every request.

    --
    Teemu Keiski
    MCP, Designer/Developer
    Mansoft tietotekniikka Oy
    [url]http://www.mansoft.fi[/url]

    AspInsiders Member, [url]www.aspinsiders.com[/url]
    ASP.NET Forums Moderator, [url]www.asp.net[/url]
    AspAlliance Columnist, [url]www.aspalliance.com[/url]

    "Robert Scheer" <rbscheer@my-deja.com> wrote in message
    news:cfd22ab6.0307250654.2cc6efd9@posting.google.c om...
    > Hi.
    >
    > Debugging one of my pages I noticed that everytime I call the page,
    > the first event to run is Page_Load and after it the Page_Unload. If I
    > postback to the page the Page_Unload runs again. Shouldn't the
    > Page_Unload event runs only when I close the page or submit the page?
    > I can't understand why the Unload event runs when I load the page !!
    >
    > Thanks,
    >
    > Robert Scheer

    Teemu Keiski Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139