Form Validation in external JavaScript File using document.getElementById
<p>My document.getElementById function is returning null on a value I know exists. Specifically I try:</p>

<pre><code>//in an external .js file
var UserName = document.getElementById('&lt;%=_username.ClientID%&gt;');
</code></pre>

<p>And test it using some conditions, which never happen due to the element id value being null. I define _username in a user control file here:</p>

<pre><code>...
&lt;fieldset class="login"&gt; 
    &lt;legend class="login"&gt;Login&lt;/legend&gt;
    &lt;label for="&lt;%=_username.ClientID%&gt;"&gt;
        User Name:&lt;/label&gt;
    &lt;asp:TextBox ID="_username" runat="server" CssClass="login" /&gt;
    &lt;label for="&lt;%=_password.ClientID%&gt;"&gt;
        Password:&lt;/label&gt;
    &lt;asp:TextBox ID="_password" runat="server" CssClass="login" TextMode="Password" /&gt;
    &lt;br /&gt;
    &lt;span class="response"&gt;
        &lt;asp:Literal ID="_response" runat="server" /&gt;&lt;/span&gt;        
    &lt;asp:Button ID="_login" runat="server" Text="Login"/&gt;
&lt;/fieldset&gt;
</code></pre>

<p>I verified my page is listening to the javascript file by testing a simpler function that doesn't require use of getElementById().</p>
