I have a simple one: if the yes switch is checked, than the text field is required. I performed a check both on the client side and on the server side. I found that:
- Client validation starts and correctly displays the failure with a warning message.
- The validation control never displays an error message and the server crashes.
- When the server crashes and the verification is completed, the control displays the correct error message.
Why does the client work correctly from the point of view of verification, but does not transmit an error message and continues to work on 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>
source
share