title: ASP.Net LoadComplete event running before Page Load?
body: <p>I need to calculate the current offset from UTC time when a page is loaded. This I can do very simply via a javascript function call as part of the page's body onload event as shown below: </p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
  
      function getOffset() {
          var curUTCDate = new Date();
          var iMins = curUTCDate.getTimezoneOffset();
          return iMins;
      }
  &lt;/script&gt;
  
  &lt;body id="bodymain" onload="javascript:document.forms[0]['hdnOffset'].value=getOffset();"&gt;
  &lt;form id="form1" runat="server"&gt;
  
      &lt;input id="hdnOffset" runat="server"/&gt;
      &lt;asp:Label ID="lblText" runat="server"&gt;&lt;/asp:Label&gt; 
  </code></pre>
  
  <p></p>
  
  <p>However when I try to use this value in the code behind as part of Page_LoadComplete on the server side the offset value has not been set as shown below </p>
  
  <pre><code>protected void Page_LoadComplete(object sender, EventArgs e)
      {
          if (!String.IsNullOrEmpty(hdnOffset.Value))
          {
              lblText.Text = hdnOffset.Value + " value set";
          }
          else
          {
              lblText.Text = " value not set ";
          }
      }
  </code></pre>
  
  <p>however the offset does become available once the Page has fully rendered as its value is now displayed in the input box. So to me this looks as if the javascript called as part of a body onload event only gets called after the Page has completely loaded.</p>
  
  <p>How is this even possible?</p>