Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A couple things to note first. MS invented a sort of "clientside runtime object" called <a href="http://msdn.microsoft.com/en-us/library/bb310856(loband).aspx" rel="noreferrer"><code>Sys.Application</code></a>. It handles raising <code>init</code>, <code>load</code>, and <code>unload</code> events throughout the [clientside] lifespan of the page, as follows:</p> <ol> <li><a href="http://msdn.microsoft.com/en-us/library/bb311012(loband).aspx" rel="noreferrer"><code>Sys.Application.initialize()</code></a> begins the <code>init</code> part of the life cycle. This <code>initialize()</code>s all clientside AJAX controls, after which they're ready to be interacted with programatically</li> <li><code>Sys.Application</code> begins the <code>load</code> part of the life cycle, calling all handlers that have subscribed to this event</li> <li>Finally, it calls the global function <code>pageLoad</code> (if one is defined)</li> </ol> <p>Step 2) and 3) are repeated for every partial (ie AJAX + UpdatePanel) postback.</p> <p><strong>So finally the answer</strong>: <code>pageLoad</code> is just a handy shortcut to <a href="http://msdn.microsoft.com/en-us/library/bb383829(loband).aspx" rel="noreferrer"><code>Sys.Application.add_load()</code></a>.</p> <p>With regards to its relationship to <code>window.onload</code> however, things start to get interesting. Essentially, MS needed <code>window.onload</code> to fire only <em>after</em> the <code>init</code> phase was complete. But you can't control when the browser will fire <code>onload</code>, as it's tied to <em>"content loaded"</em>. This is known as <a href="http://dean.edwards.name/weblog/2005/09/busted/" rel="noreferrer">"the <code>window.onload</code> problem"</a>:</p> <blockquote> <p>onload event fires after all page content has loaded (including images and other binary content). If your page includes lots of images then you may see a noticeable lag before the page becomes active.</p> </blockquote> <p>So, they just invented their own "special" function to fire at just the right time in their event life cycle and called it <code>"pageLoad"</code>. And the trick that they used to kickoff this custom event life cycle was to <a href="http://msdn.microsoft.com/en-us/library/bb311012(loband).aspx" rel="noreferrer">place the call to <code>Sys.Application.initialize()</code> just before the closing <code>&lt;/form&gt;</code> tag</a>. The serverside runtime does this. Astute readers will note that this trick allowed MS to solve the <code>window.onload</code> problem, since any code you put into <code>pageLoad</code> will fire independent of binary content (<a href="http://seejoelprogram.wordpress.com/2008/06/08/when-sysapplicationinitialize-causes-operation-aborted-in-ie/" rel="noreferrer">w/ one rare catch for IE</a>).</p> <p><strong>&gt; Do they act the same?</strong></p> <p>Conceptually yes, in practice not at all due to said <code>window.onload</code> problem. The only rule is that you should put code that interacts with your AJAX controls in <code>pageLoad</code> only, since <code>window.onload</code> follows its own event trajectory.</p> <p><strong>&gt; Or is one called before the other?</strong></p> <p>They are completely, 100% independent.</p> <p><strong>&gt; Or will one be called automatically and the another not?</strong></p> <p>They will both be called if you have them defined.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload