customvalidator onServerValidate未触发

时间:2010-11-16 02:48:28

标签: c# customvalidator

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

<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"  />

我的ServerValidate根本不会触发。

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

1 个答案:

答案 0 :(得分:1)

您是否在代码中的某处调用了Page.Validate()方法,或者提交按钮是否将CausesValidation设置为true?