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.


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}." >
      <des:TextErrorFormatter Display="Dynamic"></des:TextErrorFormatter>

Style sheet classes that affect tokens

   font-weight: bold;
   color: Maroon;
   text-decoration: underline;