【问题标题】:customvalidator onServerValidate not firingcustomvalidator onServerValidate 未触发
【发布时间】:2010-11-16 02:48:28
【问题描述】:

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

<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;
}

【问题讨论】:

    标签: c# customvalidator


    【解决方案1】:

    您是在代码后面的某处调用 Page.Validate() 方法,还是提交按钮的 CausesValidation 设置为 true?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-11
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2010-11-26
      • 2011-11-25
      • 1970-01-01
      相关资源
      最近更新 更多