How to find and modify an asp.net control with JavaScript?
<p>This has been bothering me for quite some time. I'm simply trying to change the value of a textbox defined in asp.net, which normally works when it is not within a LoggedInTemplate.</p>

<p>I've searched everywhere on the net and even here, but the only thing I can find close to doing what I need is here <a href="http://stackoverflow.com/questions/3024954/finding-an-aspbutton-and-asptextbox-in-javascript">Finding an asp:button and asp:textbox in Javascript</a>. Unfortunately that doesn't work. Here's what I have so far:</p>

<pre><code>&lt;head id="Head1" runat="server"&gt;
  &lt;script src="../../scripts/webeffects.js" type="text/javascript" language="javascript"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;asp:LoginView ID="LoginView1" runat="server"&gt;
  &lt;LoggedInTemplate&gt;
  &lt;div class="lotto_pick_container"&gt;
    &lt;table runat="server" id="tblLottoPick"&gt;
      &lt;tr&gt;&lt;th colspan="3"&gt;Pick a Lotto Number&lt;/th&gt;&lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;asp:TextBox ID="txt1stNum" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
    &lt;td&gt;&lt;asp:TextBox ID="txt2ndNum" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
    &lt;td&gt;&lt;asp:TextBox ID="txt3rdNum" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;asp:Button ID="cmdSubmitPick" runat="server" Text="Submit Lotto Number" 
        onclientclick="return validateLottoPicks()" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
  &lt;/div&gt;
  &lt;/LoggedInTemplate&gt;
&lt;/asp:LoginView&gt;
</code></pre>

<p>Right now I'm trying to use an external js script to find a textbox and modify it with an arbitrary value of 12, just so that I know it can work:</p>

<pre><code>function validateLottoPicks() {
  document.getElementById('&lt;%= LoginView1.FindControl("txt2ndNum").ClientID %&gt;').value = 12
}
</code></pre>

<p>When I debug this with Firebug it seems all my other code works, except for this one function. I have verified the function gets called, it's just this line that doesn't work. Can someone please provide some guidance? I'll send milk and cookies.</p>

<p><strong>Update:</strong></p>

<p>Thanks for all the help from everyone. This was my first time using Stack Overflow and I was definitely impressed by the quick responses.
<br />
<br />
It turns out my actual problem was that using <strong>&lt;%= LoginView1.FindControl("txt2ndNum").ClientID %></strong> does not work in external js scripts. I didn't know this. Once, I put the function in the header of my page everything worked. Now I'm going to avoid using ASP.NET controls because I don't want to deal with that again, and it makes more sense if I ever decide to use something other than ASP.NET.
<br /></p>
