Return to the menu   Select another DES Module

Condition classes

Condition classes evaluate something about your page and return “success”, “failed”, or “cannot evaluate”. They are the underlying evaluation rule of the DES Validators, and appear in many other controls and situations in validation that include:

  • MultiConditionValidator is powered by these objects. It defines a boolean expression where each boolean value is determined by the Condition object.

    CountTrueConditionsValidator is similar. Instead of creating a boolean expression, it counts the number of Conditions that return "success".

  • Enabler property on Validators, FieldStateController, and CalculationControllers. It enables and disables the Validators, FieldStateControllers, and CalculationController control based on the control the Condition evaluates.
  • Condition property on FieldStateController and MultiFieldStateController. This is used to select between the ConditionTrue and ConditionFalse properties.
  • ConditionCalcItem object for CalculationControllers. This is used to build IF ELSE logic into your calculation based on the state of the page.

Licensing note: Most Condition classes require a license covering the Peter’s Professional Validation or Peter’s More Validators modules based on the associated Validator’s license. Only the Non-Data Entry conditions are available without a license.

Conditions available to the DES controls

Class name (in the name space PeterBlum.DES.Web.WebControls)EvaluatesDescription
RequiredTextCondition Strings Tests if a field’s textual value is “blank” or not. You can define what text represents “blank”.
RegexCondition Strings Tests a field’s textual value against a regular expression. Use it to confirm the text fits a pattern such as a phone number, email address, or postal code.
DataTypeCheckCondition Strings, numbers, dates, times Tests a field’s textual value to confirm it represents a particular data type.
RangeCondition Strings, numbers, dates, times Tests a field’s textual value is between a minimum and maximum value. You determine the data type of the values.
CompareToValueCondition Strings, numbers, dates, times Tests a field’s textual value against another value that you supply. You determine the data type of the values and the operator to compare the two.
CompareTwoFieldsCondition Strings, numbers, dates, times Tests the values of two fields to each other. You select the operator that is used in the comparison.
DifferenceCondition Strings, numbers, dates, times Evaluates two textbox fields to determine if the difference between their two values is a certain number apart from each other. You select the data type (including dates), a value to compare and the operator. For example, test that two dates are less than 60 days apart.
TextLengthCondition Strings Evaluates the number of characters in a textbox against a minimum and/or maximum.
CharacterCondition Strings Tests a field’s textual value to confirm that each character is in a character set that you specify. For example, you require a password to be letters, digits, and underscores only. This Condition doesn’t care about the order or pattern of characters.
CompareToStringsValidator Strings Tests a field’s textual value against a list of strings. If the text matches one of the strings, it is valid.
MultipleRequiredControlsCondition Controls Tests several fields to determine how many have been filled in (not “blank”). It supports these rules: All, All or none, Only one, At least one, and a range.
WordCountCondition Strings Evaluates the number of words in a textbox against a minimum and/or maximum.
UnwantedWordsCondition Strings Compares a list of words to the text. It reports an error when any of the words is found within the text.
EmailAddressCondition Strings Used on Email address fields. Confirms that the pattern is valid on both client and server side.
CreditCardNumberCondition Strings Confirms that the pattern is valid for credit card numbers. Its evaluation rules confirm that the text is all digits, follows Luhn’s formula, and if desired matches specific brands of credit cards. It does not provide credit card number approval.
ABARoutingNumberCondition Strings Confirms that the pattern is valid for ABA routing numbers such as check routing numbers. It confirms that the text is always 9 digits that are confirmed with a checksum rule defined by the American Bankers Association.
DuplicateEntryCondition TextBox and list controls Determines if three or textboxes, dropdownlists, or lists have a matching value. It reports an error when a duplicate is found.
RequiredListCondition List controls Tests if a list-style control is “unselected”.
SelectedIndexCondition List controls Evaluates a specific index in the list style control to see if its selected or unselected.
SelectedIndexRangesCondition List controls Evaluates the selected index against a list of valid indices.
CountSelectionsCondition List controls Evaluates CheckBoxLists and multi-selection ListBoxes to determine how many items are selected and compares the result of a range.
ListSizeCondition List controls Evaluates the number of items shown in a listbox or dropdownlist. Typically used when the user interface allows adding and removing items in a list, where you have a minimum or maximum for the number of items shown.
CheckStateCondition Booleans, CheckBoxes, and RadioButtons Evaluates the value of a Checkbox, Radiobutton, or Boolean value.
RequiredSelectionCondition Controls For controls that have can have an unselected value, such as Calendar, MultiSelectionCalendar, MonthYearPicker, TimePicker, DataList, and ListView. Determines if the control has a selected value.
VisibleCondition HTML attribute Evaluates a control’s visible state. This does NOT evaluate the Control’s own Visible property because that prevents generating HTML. It evaluates the HTML generated to see if its styled to be visible.

Usage: Assign the ControlIDToEvaluate to the control and set IsVisible to true or false.

EnabledCondition HTML attribute Evaluates a control’s enabled state.

Usage: Assign the ControlIDToEvaluate to the control and set IsEnabled to true or false.

ClassNameCondition HTML attribute Evaluates the a control’s style sheet name.

Usage: Assign the ControlIDToEvaluate to the control and set ClassName to the style sheet class name to match.

ReadOnlyCondition HTML attribute Evaluates a textbox’s readonly state.

Usage: Assign the ControlIDToEvaluate to the control and set IsReadOnly to true or false.

CompareToValueAttributeCondition HTML attribute Evaluates an HTML attribute or style’s value.

Usage: Assign the ControlIDToEvaluate to the control. Specify the name of the attribute or style in AttributeName. Use Value and Operator for how to match. Set AttributeType to Style to look for a style.

MultiCondition Other conditions Builds a boolean expression from any Condition objects, such as “RequiredTextCondition on TextBox1 AND CheckStateCondition on CheckBox1”. This Validator often replaces the need for custom Validators.
CountTrueConditions Other conditions Lets you define a list of Condition objects to evaluate a number of fields. Evaluates how many of those conditions are true and compares them to a minimum and maximum. A common usage is to count the number of marked CheckBoxes in a column of a DataList, ListView, Repeater, or GridView.
CustomCondition Up to you Build your own evaluation rules. It supports client- and server-side evaluations.

Conditions available to your code

Most Condition classes get data from controls on the page. There are cases where you just want to pass a string, boolean, number, or other value to be evaluated. Most Condition classes can help. They have a ValueToEvaluate or ValueToEvaluateAsNative property which you use instead of the ControlIDToEvaluate property.

If you use the same Condition classes from the PeterBlum.DES.Web.WebControls namespace, above, you will get a lot of overhead designed to handle the special issues of controls. To avoid that overhead, DES includes the same-named Condition classes in the PeterBlum.DES.Neutral namespace (except CheckStateCondition is called CompareBooleanCondition and any Condition designed explicitly for controls is not defined here.)


Return to the menu   Select another DES Module