I'm using a bunch of different asp.net validation controls on a web form. Some of these have their Text property set to things like "* Error" or "You missed these fields".
我在Web表单上使用了一堆不同的asp.net验证控件。其中一些将其Text属性设置为“* Error”或“您错过了这些字段”之类的内容。
However, a few of the CustomValidator controls have blank Text properties. I left them blank on purpose because I'm adding the ErrorMessage dynamically depending on which case fails. (A CustomValidator may have many different conditions upon which I set args.IsValid = false)
但是,一些CustomValidator控件具有空白Text属性。我故意将它们留空,因为我根据哪种情况失败动态添加ErrorMessage。 (CustomValidator可能有许多不同的条件,我设置args.IsValid = false)
When an error occurs, the ErrorMessage property that I set is shown both in the ValidationSummary and inside the Validator control. I don't want that. I want to be able to just show the ErrorMessage in the ValidationSummary and not in the BaseValidator.Text property.
发生错误时,我设置的ErrorMessage属性将显示在ValidationSummary和Validator控件内。我不希望这样。我希望能够在ValidationSummary中显示ErrorMessage,而不是在BaseValidator.Text属性中显示。
My first try was to set the Text property to be a space " ". That didn't work.
我的第一个尝试是将Text属性设置为空格“”。那没用。
What I implemented (for now) is a period that is shown as the same color of the background. It's a hack - and I don't like it. Heck, maybe that's why I'm here!
我实现的(现在)是一个显示为背景颜色相同的时期。这是一个黑客 - 我不喜欢它。哎呀,也许这就是我在这里的原因!
Here's the code:
这是代码:
<asp:CustomValidator ID="*Validator" runat="server"
Text="."
CssClass="validatorstyle"
Display="Dynamic"
OnServerValidate="validate_AllowedToDoSomething"
ValidationGroup="MainGroup" />
<asp:ValidationSummary ID="mainGroupValidationSummary" runat="server"
ValidationGroup="MainGroup"
DisplayMode="BulletList"
HeaderText="There was an error in saving. Please check the following:" />
Inside validate_AllowedToDoSomething I call:
在validate_AllowedToDoSomething里面我打电话:
*Validator.ErrorMessage = "Custom Error Message #1";
args.IsValid = false;
return;
What I get is "Custom Error Message #1" twice on the web form. Thanks in advance!
我得到的是在Web表单上两次“自定义错误消息#1”。提前致谢!
1 个解决方案
#1
Just set display="none"
instead of "dynamic"
on the BaseValidator, and that should solve it.
只需在BaseValidator上设置display =“none”而不是“dynamic”,这应该可以解决它。
#1
Just set display="none"
instead of "dynamic"
on the BaseValidator, and that should solve it.
只需在BaseValidator上设置display =“none”而不是“dynamic”,这应该可以解决它。