title: "getElementById returns undefined" when accessing asp:HiddenField in JavaScript?
body: <p>I have MasterPage/ContentPage, where in <code>ContentPage.aspx</code> file i have <code>java-script</code> code. I want to move the java-script code out of <code>ContentPage.aspx</code> to a separate js file and do the following:</p>
  
  <p>//in ContentPage.aspx</p>
  
  <pre><code>&lt;script type="text/javascript" src='&lt;%= ResolveClientUrl("~/file1.js") %&gt;'&gt;&lt;/script&gt;
  </code></pre>
  
  <p>In file1.js i copy and paste all java-script code. On the java-script code, i have a cide line:</p>
  
  <p>//file1.js:</p>
  
  <pre><code>var hiddenvar1 = document.getElementById('&lt;%=hiddenvariable1.ClientID%&gt;');
  </code></pre>
  
  <p>..then and i cannot get the value of that variable (hiddenvar1.value) because object hiddenvar1 is null. The javascript code was working when it was inside ContentPage.aspx. When i moved it to file1.js it's not working anymore. </p>