title: Move JavaScript to an external file when it has document.getElementById('<%= control.ClientID%>') in it
body: <p>I have an existing ASP.NET web page with a few hundred lines of JavaScript code inline on the page.</p>
  
  <p>The code is full of code that references server-side control names, such as this:</p>
  
  <pre><code>  function SetVisibility(isVisible) {
      document.getElementById('&lt;%=someDiv.ClientID%&gt;').style.display = (isVisible ? "block" : "none");
    }
  </code></pre>
  
  <p>If I move the script to an external .JS file, the .ClientID references are no longer resolved, and the page collapses in a pile of errors.</p>
  
  <p>What is the best way to solve this problem?  I can change every function to take controls as arguments, or I can replace the .getElementByID with $find()... but I'm hoping there is an easier/faster way.</p>