I’m just trying to access the value of a textbox control (which has the runat=”server” attribute). Been stuck for hours looking for an answer. Every time I try to get the value, it is null.
The javascript file:
function validateRegistration() {
var username = document.getElementById("<%=username.ClientId%>").value;
document.write(username);
}
The aspx file:
<asp:Content ID="Content3" ContentPlaceHolderID="mainContentPlaceHolder" runat="server">
<p>
Fill in the following form to register:</p>
<p>
Username:
<asp:TextBox ID="username" name="username" runat="server"></asp:TextBox></p>
<input id="register" type="submit" value="Register" onclick="validateRegistration()"/>
</asp:Content>
Did you try using
var username = document.getElementById('<%= username.ClientID%>').value;?i have similar code in my page and works fine.