我有一个页面,其中包含几个必填字段验证器,我创建了一个自定义字段验证器来检查两个文本框,一个或另一个是必需的,但不是两个都需要。如果我将文本添加到其中一个文本框,然后跳出ClientValidationFunction,则将触发。如果我将文本添加到框中,然后单击提交而不失去焦点,则ClientValidationFunction不会触发。
function checkGrievanceProcedure(source, args){
var GrievanceProcedure = $('#<%=txtGrievanceProcedure.ClientID%>').val();
var GrievanceProcedureURL = $('#<%=txtGrievanceProcedureURL.ClientID%>').val();
if (GrievanceProcedure.length <= 0 && GrievanceProcedureURL.length <= 0) {
args.IsValid = false;
return;
}
args.IsValid = true;
}
ASP.NET
<asp:TextBox ID="txtGrievanceProcedure" runat="server" Width="300" TextMode="MultiLine" Height="100"></asp:TextBox>
<asp:CustomValidator ID="cvGrievanceProcedure" runat="server" ControlToValidate="txtGrievanceProcedure"
ErrorMessage="<%$ Resources: GrievanceProcedureInstruction %>"
ClientValidationFunction="checkGrievanceProcedure"></asp:CustomValidator>
<asp:TextBox ID="txtGrievanceProcedureURL" runat="server" Width="300" MaxLength="200"></asp:TextBox>
<asp:CustomValidator ID="cvGrievanceProcedure" runat="server" ControlToValidate="txtGrievanceProcedure"
ErrorMessage="<%$ Resources: GrievanceProcedureInstruction %>"
ClientValidationFunction="checkGrievanceProcedure"></asp:CustomValidator>
<asp:Button ClickOnce="true" ID="btnNext" runat="server" CssClass="formbutt" OnClick="Save" Text="<%$ Resources: Resource, Save%>" />