Can you explain why the function ValidatorValidate(v)
validates all the RequiredFieldValidator
controls on the page instead of just executing for RequiredFieldValidator1
? Here is the code snippet:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function check() {
var v = document.getElementById("<%=RequiredFieldValidator1.ClientID%>");
ValidatorValidate(v);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox2"></asp:RequiredFieldValidator>
<br />
<asp:Button ID="Button1" runat="server" OnClientClick="check()" Text="Check" />
</div>
</form>
</body>
</html>