我有一个要求,多个字段中的一个是必需的。使用自定义验证器时,将返回even fires,false,但不显示任何错误消息,并验证表单。
我遗漏了什么?我尝试过使用和不使用ValidationSummary。
谢谢!
<asp:CustomValidator ID="CustomValidator1" OnServerValidate="validatePhone" EnableClientScript="false" runat="server" ErrorMessage="Home or Cell Phone is Required" ></asp:CustomValidator>
<asp:ValidationSummary ID="ValidationSummary1" DisplayMode="BulletList" runat="server" ForeColor="Red" Font-Size="X-Small" Font-Bold="true" />
protected void validatePhone(object sender, ServerValidateEventArgs e)
{
e.IsValid = string.IsNullOrEmpty(txtCellPhone.Text) && string.IsNullOrEmpty(txtHomePhone.Text) ? false : true;
}发布于 2010-11-04 06:54:28
您必须将ControlToValidate设置为某个TextBox。
<asp:CustomValidator ID="CustomValidator1" OnServerValidate="validatePhone" EnabEnableClientScript="false" runat="server" ErrorMessage="Home or Cell Phone is Required" ControlToValidate="txtHomePhone"/>https://stackoverflow.com/questions/4092366
复制相似问题