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".
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)
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.
My first try was to set the Text property to be a space " ". That didn't work.
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="StackOverflowValidator" 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:
StackOverflowValidator.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!