我有一个 CustomValidator 并定义了它的所有可能参数:
<asp:CustomValidator ID="custom" runat="server" Text="*" ErrorMessage="This email address is already registered" ControlToValidate="txtEmail" OnServerValidate="isExist" Display="None" ValidationGroup="valRegister"></asp:CustomValidator>
PS:我有同一个文本框的RequiredFieldValidator,我不想检查空值。
以下是表单的其他对象:
<div class="row"><asp:Label runat="server" Text="Email" AssociatedControlID="txtEmail"></asp:Label><asp:RequiredFieldValidator runat="server" ErrorMessage="Please enter your email" Text="*" ControlToValidate="txtEmail"></asp:RequiredFieldValidator><asp:TextBox ID="txtEmail" runat="server" CssClass="inpBox"></asp:TextBox></div>
<asp:Button runat="server" Text="Register" CssClass="btn" OnClick="register_member" CausesValidation="true" ValidationGroup="valRegister" />
<asp:ValidationSummary ID="validationSummary" runat="server" ShowMessageBox="true" ShowSummary="false" ValidationGroup="valRegister" />
protected void isExist(object sender, ServerValidateEventArgs args){
if (cre.member.isExist(args.Value)){
args.IsValid = false;
} else {
args.IsValid = true;
}
}
当我把一个已经存在于数据库表中的电子邮件 * 出现在表单上时,但没有显示错误消息。我尝试了自定义错误的所有显示选项,但没有运气。