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.
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 Finding an asp:button and asp:textbox in Javascript. Unfortunately that doesn't work. Here's what I have so far:
<head id="Head1" runat="server">
<script src="../../scripts/webeffects.js" type="text/javascript" language="javascript"></script>
</head>
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
<div class="lotto_pick_container">
<table runat="server" id="tblLottoPick">
<tr><th colspan="3">Pick a Lotto Number</th></tr>
<tr>
<td><asp:TextBox ID="txt1stNum" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="txt2ndNum" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="txt3rdNum" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Button ID="cmdSubmitPick" runat="server" Text="Submit Lotto Number"
onclientclick="return validateLottoPicks()" /></td>
</tr>
</table>
</div>
</LoggedInTemplate>
</asp:LoginView>
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:
function validateLottoPicks() {
document.getElementById('<%= LoginView1.FindControl("txt2ndNum").ClientID %>').value = 12
}
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.
Update:
Thanks for all the help from everyone. This was my first time using Stack Overflow and I was definitely impressed by the quick responses.
It turns out my actual problem was that using <%= LoginView1.FindControl("txt2ndNum").ClientID %> 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.