CustomValidator fires on the client but the validation control does not render when validation fails
asp.net
Solution
Use `args.IsValid` instead of `args.isValid`
function testClientValidation(src, args) {
if ($('#<%=rblstTest.ClientID%>' + ' input:checked').length == 1) {
if ($('#<%=rblstTest.ClientID%>' + ' input:checked').val().toLowerCase() == "yes") {
args.IsValid = !($('#<%=txtTest.ClientID%>').val() == "");
} else {
args.IsValid = true;
}
} else {
args.IsValid = true;
}
alert(args.IsValid);
}
Problem
I have a simple: If the 'yes' radio button is checked than make the text box required situation. I have supplied both client and server-side validation. What I'm finding is that: - Client validation is firing and displaying failure correctly via an alert message. - The validation control never renders an error message and the server is hit. - When the server is hit and validation fails, the control renders the proper error message. Why is the client working correctly in terms of validating, but not rendering an error message and continuing on to the server? ``` asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> <script src="Scripts/jquery-1.7.2.js" type="text/javascript"></script> <script type="text/javascript"> function testClientValidation(src, args) { if ($('#<%=rblstTest.ClientID%>' + ' input:checked').length == 1) { if ($('#<%=rblstTest.ClientID%>' + ' input:checked').val().toLowerCase() == "yes") { args.isValid = !($('#<%=txtTest.ClientID%>').val() == ""); } else { args.isValid = true; } } else { args.isValid = true; } alert(args.isValid); } </script> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <div> <asp:RadioButtonList ID="rblstTest" RepeatDirection="Horizontal" RepeatLayout="Flow" runat="server"> <asp:ListItem>Yes</asp:ListItem> <asp:ListItem>No</asp:ListItem> </asp:RadioButtonList> <asp:TextBox ID="txtTest" runat="server"/> <asp:CustomValidator ID="cust" ControlToValidate="rblstTest" OnServerValidate="testSeverValidation" ClientValidationFunction="testClientValidation" Display="Dynamic" ErrorMessage="Error!" runat="server"/> <asp:LinkButton runat="server" ID="lnkSubmit" Text="Submit" /> </div> </asp:Content> ```