title: Find an element by id within a dynamically added control
body: <p>I have an asp page in which I add dynamically a control I created (several times). In that control I have textbox for password and username and a revert button.</p>
  
  <p>I use this javascript code in that control and it fails:</p>
  
  <pre><code>function HandlePasswordChanged() {
      document.getElementById("&lt;%=btnRevert.ClientID %&gt;").disabled = false;
  }
  function HandleUserChanged() {
      document.getElementById("&lt;%=btnRevert.ClientID %&gt;").disabled = false;
      document.getElementById("&lt;%=txtPassword.ClientID %&gt;").disabled = false;
  }
  function btnRevertClick() {
      document.getElementById("&lt;%=btnRevert.ClientID %&gt;").disabled = true;
      document.getElementById("&lt;%=txtPassword.ClientID %&gt;").disabled = true;
      document.getElementById("&lt;%=txtUsername.ClientID %&gt;").value = document.getElementById("&lt;%=systemAccount.ClientID %&gt;").value;
      document.getElementById("&lt;%=txtPassword.ClientID %&gt;").value = "";
  }
  </code></pre>
  
  <p>what it does is when I press the revert button on one control it disables the textbox on the other control - getelement fails to find the correct one.</p>
  
  <p>How can I fix this?</p>