C# 服务器上的customvalidator验证程序未启动

C# 服务器上的customvalidator验证程序未启动,c#,customvalidator,C#,Customvalidator,我有一个单选按钮列表和文本框都与验证 <asp:RadioButtonList ID="member" runat="server" RepeatDirection="Horizontal"> <asp:ListItem>Yes</asp:ListItem> <asp:ListItem>No</asp:ListItem> </asp:RadioButtonList> <asp:requiredfiel

我有一个单选按钮列表和文本框都与验证

<asp:RadioButtonList ID="member" runat="server" RepeatDirection="Horizontal">
    <asp:ListItem>Yes</asp:ListItem>
    <asp:ListItem>No</asp:ListItem>
</asp:RadioButtonList>

<asp:requiredfieldvalidator id="unionvalidator" runat="server" controltovalidate="member" errormessage="Required" />

Required if member == "yes"

<asp:TextBox runat="server" ID="union"></asp:TextBox>
<asp:customvalidator ID="Customvalidator1" runat="server" ValidateEmptyText="true" onServerValidate="UnionValidate" errormessage="Your current union is required"  />

您是在代码背后的某个地方调用Page.Validate()方法,还是“提交”按钮将CausesValidation设置为true

public void UnionValidate(object source, ServerValidateEventArgs args)
{
    if (member.Text == "yes" && union.Text.Trim() == "")
        args.IsValid = false;
}