我只是想访问一个文本框控件的值(它具有 runat="server" 属性)。被困了几个小时寻找答案。每次我尝试获取该值时,它都是空的。
javascript文件:
function validateRegistration() {
var username = document.getElementById("<%=username.ClientId%>").value;
document.write(username);
}
.aspx 文件:
<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>