This is the code from the .aspx file
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login Again</title>
<script type="text/javascript">
function Validate() {
if (document.getElementById("txtLogin").value == "") {
alert("Enter login name.");
}
if (document.getElementById("<%=txtLogin.ClientID%>").value == "") {
alert("Enter login name.");
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="txtLogin" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Login" OnClientClick="Validate()" />
</form>
</body>
</html>
In the Validate () function, I can access a text field using a control identifier i.e.; getElementById("txtLogin")so should one use a second approach that accesses control through
control.ClientIDand why?
My first understanding was that server access control I should use this syntax <%= %>, but now I come to know from this example that I can access the server on the server side simply through
getElementById("ID-of-control").
source
share