Return to the menu   Select another DES Module

Demonstrates the WordCountValidator

The WordCountValidator evaluates the number of words in a textbox against a minimum and/or maximum. It can optionally evaluate the total words in two textboxes.

If you want an interactive view to the word count, use the TextCounter control.

Specify the control to evaluate with the ControlIDToEvaluate property; if you want to evaluate the combined length of two controls, specify the second in SecondControlIDToEvaluate.

The Minimum and Maximum properties determine the limits when they are not 0. When using the Minimum property, if you do not want errors reported for an empty textbox, set IgnoreBlankText to true.

The ErrorMessage and SummaryErrorMessage properties support these tokens.

  • “{COUNT}” - The number of characters entered.
  • “{EXCEEDS}” - The number of characters exceeding the minimum or maximum.
  • “{EXCEEDS:singular:plural}” uses the singular word when {EXCEEDS} is 1; otherwise it uses the plural word.
  • “{MINIMUM}” - The value of the Minimum property.
  • “{MAXIMUM}” - The value of the Maximum property.


Controls

Maximum

Enter words. Maximum=10



Minimum using various tokens

Enter words. Minimum=5




Source Code (C#)

<script runat="server">
protected void Button1_Click(object sender, EventArgs e) { if (PeterBlum.DES.Globals.WebFormDirector.IsValid) { // save your data here } }
</script> <h2>Maximum</h2> Enter words. Maximum=10<br/><br/> <asp:TextBox ID="TextBox1" runat="server" Style="width:500px;"></asp:TextBox> <des:WordCountValidator ID="WordCountValidator1" runat="server" ControlIDToEvaluate="TextBox1" ErrorMessage="You have exceeded the limit of {MAXIMUM} words" Maximum="10"> </des:WordCountValidator> <br/> <br/> <h2>Minimum using various tokens</h2> Enter words. Minimum=5<br/><br/> <asp:TextBox ID="TextBox2" runat="server" Style="width:500px;"></asp:TextBox> <des:WordCountValidator ID="WordCountValidator2" runat="server" ControlIDToEvaluate="TextBox2" ErrorMessage="You have entered {COUNT} which is {EXCEEDS} {EXCEEDS:word:words} less than {MINIMUM}." Minimum="5"> </des:WordCountValidator> <br/> <br/> <des:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click"></des:Button>

Return to the menu   Select another DES Module