title: asp.net external JavaScript file doesn't find Control.ClientID
body: <p>On load I'm both calling a JavaScript setTimeout() function that will hide a .NET Panel control, and hiding it in the code behind on first load.  Clicking the save button will set the Panel to visible then reload the page at which point a setTimeout() function is called... so basically you click save, and see a panel with "Details Saved" for three seconds, at which point it disappears.</p>
  
  <p>The problem is the external JavaScript file can't find _pDivAlert.ClientID (I've debugged and it returns null).  It only works when the code is in a  tag in the .aspx page.  Any suggestions as to how I can either pass the client ID to the HideControl() function or find the ClientID from the external JS file?</p>
  
  <p>Here's my code, any suggestions?  </p>
  
  <pre><code>&lt;script language="javascript" src="Forms.js" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;body onload="ToggleAlert()"&gt;
  &lt;form id="form1" runat="server"&gt;
  &lt;script type="text/javascript"&gt;
      //alert the user that the details were saved
      function HideControl() {
          var control = document.getElementById('&lt;%=_pDivAlert.ClientID %&gt;');
          if(control != null)
              control.style.display = 'none';
      }
      function ToggleAlert() {
          setTimeout("HideControl()", 3000);
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>I've also tried sending the ClientID within the ToggleAlert() call, but that didn't work:</p>
  
  <pre><code>&lt;body onload="ToggleAlert('&lt;%=_pDivAlert.ClientID %&gt;')"&gt;
  </code></pre>
  
  <p>External JS:</p>
  
  <pre><code>function HideControl(_c) {
  var control = _c;
  if (control != null)
      control.style.display = 'none';
  }
  function ToggleAlert(_c) {
      setTimeout("HideControl(_c)", 3000);
  }
  </code></pre>