本文介绍了自定义验证器没有显示错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个字段中的一个是必需的要求。使用自定义验证程序甚至火灾,返回false,但没有错误信息显示和形式验证。

我在想什么?我曾尝试与无的ValidationSummary。

谢谢!

 < ASP:的CustomValidator ID =CustomValidator1OnServerValidate =validatePhoneEnableClientScript =假=服务器的ErrorMessage =首页或手机是必需的>&LT ; / ASP:的CustomValidator>< ASP:的ValidationSummary ID =ValidationSummary1DISPLAYMODE =BulletList=服务器前景色=红FONT-SIZE =X-小字体粗体=真/>
保护无效validatePhone(对象发件人,ServerValidateEventArgs E)
    {
        e.IsValid = string.IsNullOrEmpty(txtCellPhone.Text)及&放大器; string.IsNullOrEmpty(txtHomePhone.Text)?假:真实的;
    }


解决方案

问题完全是我的错。在我的提交按钮我做的最后一件事是Response.Redirect的。该消息接踵而来,但随后谢谢页的是presented。现在,只有做的Response.Redirect如果的CustomValidator返回true。

I have a requirement that one of multiple fields is required. Using custom validator the even fires, false is returned, but no error message is display and the form validates.

What am I missing? I have tried with and without ValidationSummary.

Thanks!

<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;
    }
解决方案

Issue was completely my fault. On my submit button the final thing I do is a Response.Redirect. The message was coming up, but then the Thank you page was being presented. Now only doing the Response.Redirect if the customvalidator returns true.

这篇关于自定义验证器没有显示错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 14:08