Home     About PeterBlum.com     Policies     Download a Licensed Product     Newsletter
Peter's Professional Validation
Tokens in Error Messages

While the ErrorFormatter adds formatting around the error message, you may want changes within the error message. There are two ways to customize the error message itself:

  • Tokens that display the Label property, various other design time properties, and runtime values.
  • Style sheets applied around those tokens.

Both are shown here.

Demo

This example shows a textbox with label. The validator is a TextLengthValidator that compares the number of characters in the textbox to a minimum and maximum. For this demo, the minimum is 5 and maximum is 10. The ErrorMessage property contains this value:

You have entered {COUNT} {COUNT:character:characters} on {LABEL}. Please enter between {MINIMUM} and {MAXIMUM}.

Enter any number of characters above 10 or below 5 and tab off to see the error message.

Field Label

ASP.NET Syntax for this demo

<asp:Label id=Label1 runat="server">Field Label</asp:Label>
<asp:TextBox id=TextBox1 runat="server" Width="323px"></asp:TextBox>
<des:TextLengthValidator id=TextLengthValidator1 runat="server" 
   ControlIDToEvaluate="TextBox1" Minimum="5" Maximum="10" Label-LabelControlID="Label1"
   ErrorMessage="You have entered {COUNT} {COUNT:character:characters} on {LABEL}. Please enter between {MINIMUM} and {MAXIMUM}." >
   <ErrorFormatterContainer>
      <des:TextErrorFormatter Display="Dynamic"></des:TextErrorFormatter>
   </ErrorFormatterContainer>
</des:TextLengthValidator>

Style sheet classes that affect tokens

.DESVALLabelToken
{
   font-weight: bold;
}
.DESVALRuntimeToken
{
   color: Maroon;
}
.DESVALPropertyToken
{
   text-decoration: underline;
}