title: Master, Partials Rendering and Javascript Calls
body: <p>I'd like to understand the order of things that occur once there is a master page, a partial and some javascript code.</p>
  
  <p>Let's say I have a Master page with scripts:</p>
  
  <pre><code>&lt;%@ Master Language="C#" ... %&gt;
  
  &lt;head&gt;
      &lt;asp:ContentPlaceHolder ID="HeadContent" runat="server" /&gt;
      // header stuff
  &lt;/head&gt;
  
  &lt;body&gt;
  // Html stuff here
  
  &lt;/body&gt;
  
  &lt;script type="text/javascript"&gt;
       function foo () {
  };
  &lt;/script&gt;
  </code></pre>
  
  <p>Now I have  a page, Index.aspx, that inherits from this Master page and has this in it:</p>
  
  <pre><code>&lt;script type="text/javascipt"&gt;
      foo();
  &lt;/script&gt;
  </code></pre>
  
  <p>What happens is I get <code>"foo() is not defined"</code> error message in my chrome's console, while if I take the script chunk from the Master page and move it to its header, everything works fine.</p>
  
  <p>So my questions are - </p>
  
  <ol>
  <li><p>what is the order of things, and what happens first ?
  Does the Index.aspx rendering occur before the Master page fully loads so the Index.aspx page does not yet know what is defined on the bottom of the Master page ? (and it's fine if it's on the top?) 
  I believe the answer is yes to this one.</p></li>
  <li><p>The more puzzling question - if the rendering of the Master page is not yet fully finished on the server side, how is javascript from the Index.aspx page called? 
  To phrase this equivalently - If I have an A page rendering B rendering C rendering (and so forth), is the first javascript that's gonna get called is the one on C's page (or the last one being called)?</p></li>
  </ol>