Return to the menu   Select another DES Module

Demonstrates the DifferenceValidator

The DifferenceValidator compares a field’s value to another field's value. It ensures the two values are separated by a minimum or maximum value. Specify the IDs of the two fields in the ControlIDToEvaluate and SecondControlIDToEvaluate properties.

Unless the data entry control is DES data type entry textbox (like DateTextBox or IntegerTextBox), always remember to set the DataType property. It supports these values: “String-Case Insensitive”, “Integer”, “Double”, “Date”, “Currency”, “Currency with Symbol”, “Positive Integer”, “Positive Double”, “Positive Currency”, and “Positive Currency with Symbol”. DES data type entry textboxes automatically supply their own datatype.

Use the DifferenceValue to specify a number for the minimum or maximum difference. Set the Operator property to LessThan or LessThanEquals if DifferenceValue is a maximum. Set it to GreaterThan or GreaterThanEquals if DifferenceValue is a minimum.

A value of "1" could have several meanings: days, hours, minutes, months, thousands, etc. Use the OneEquals property to override the default meaning for one. (Date defaults to "day", time defaults to "seconds", numbers default to 1=1.)

The ErrorMessage and SummaryErrorMessage properties support these tokens:

  • "{DIFFERENCEVALUE}" - The value of the DifferenceValue property.
  • "{DIFFRESULT}" - The calculated difference.

When entering values, you will notice a delay in showing the error message until focus as left both fields. If you want the error message to show on any focus change, set ReportsErrorsAfter to "EachEdit".


Controls

Textboxes used for integer entry

Enter integers. To be valid, the fields must be a minimum of 10 apart.

Between and

IntegerTextBox

Any of DES's data type entry textboxes (integer, decimal, date, etc) do not require setting the DataType property.
Enter integers. To be valid, the fields must be no more than 10 apart.

Between and

DurationTextBoxes

This shows the OneEquals property. Normally times and durations consider DifferenceValue of 1 to be in seconds. This time it is in hours.
Enter durations. To be valid, the fields must be no more than 10 hours apart.

Between and

DES Calendar

The first calendar must have a selected dates at least 10 days apart.
When using the Calendar, the DifferenceValidator.DataType property can be omitted.

Previous Month
Next Month
November 2024 Select a Different Month
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567
Clear
Previous Month
Next Month
November 2024 Select a Different Month
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567
Clear


See also:
On DateTextBoxes
On TimeOfDayTextBox and DurationTextBox

 

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>Textboxes used for integer entry</h2> Enter integers. To be valid, the fields must be a minimum of 10 apart.<br/><br/> Between <des:TextBox ID="TextBox1" runat="server" ></des:TextBox> and <des:TextBox ID="TextBox2" runat="server" ></des:TextBox> <des:DifferenceValidator ID="DifferenceValidator1" runat="server" ControlIDToEvaluate="TextBox1" SecondControlIDToEvaluate="TextBox2" DataType="Integer" Operator="GreaterThanEqual" DifferenceValue="10" ErrorMessage="The fields must be at least {DIFFERENCEVALUE} apart. They are currently {DIFFRESULT} apart."> <ErrorFormatterContainer> <des:TextErrorFormatter Display="Dynamic" /> </ErrorFormatterContainer> </des:DifferenceValidator> <des:DataTypeCheckValidator ID="DataTypeCheckValidator1" runat="server" ControlIDToEvaluate="TextBox1" DataType="Integer" ErrorMessage="Enter an integer in TextBox1."> <ErrorFormatterContainer> <des:TextErrorFormatter Display="Dynamic" /> </ErrorFormatterContainer> </des:DataTypeCheckValidator> <des:DataTypeCheckValidator ID="DataTypeCheckValidator2" runat="server" ControlIDToEvaluate="TextBox2" DataType="Integer" ErrorMessage="Enter an integer in TextBox2."> <ErrorFormatterContainer> <des:TextErrorFormatter Display="Dynamic" /> </ErrorFormatterContainer> </des:DataTypeCheckValidator> <br/><br/> <h2>IntegerTextBox</h2> Any of DES's data type entry textboxes (integer, decimal, date, etc) do not require setting the <span class="PropertyName">DataType</span> property.<br/> Enter integers. To be valid, the fields must be no more than 10 apart.<br/><br/> Between <des:IntegerTextBox ID="IntegerTextBox1" runat="server" ></des:IntegerTextBox> and <des:IntegerTextBox ID="IntegerTextBox2" runat="server" ></des:IntegerTextBox> <des:DifferenceValidator ID="DifferenceValidator2" runat="server" ControlIDToEvaluate="IntegerTextBox1" SecondControlIDToEvaluate="IntegerTextBox2" DataType="Integer" Operator="LessThanEqual" DifferenceValue="10" ErrorMessage="The fields must be no more than {DIFFERENCEVALUE} apart. They are currently {DIFFRESULT} apart."> <ErrorFormatterContainer> <des:TextErrorFormatter Display="Dynamic" /> </ErrorFormatterContainer> </des:DifferenceValidator> <des:DataTypeCheckValidator ID="DataTypeCheckValidator3" runat="server" ControlIDToEvaluate="IntegerTextBox1" ErrorMessage="Enter an integer in IntegerTextBox1."> <ErrorFormatterContainer> <des:TextErrorFormatter Display="Dynamic" /> </ErrorFormatterContainer> </des:DataTypeCheckValidator> <des:DataTypeCheckValidator ID="DataTypeCheckValidator4" runat="server" ControlIDToEvaluate="IntegerTextBox2" ErrorMessage="Enter an integer in IntegerTextBox2."> <ErrorFormatterContainer> <des:TextErrorFormatter Display="Dynamic" /> </ErrorFormatterContainer> </des:DataTypeCheckValidator> <br/><br/> <h2>DurationTextBoxes</h2> This shows the <span class="PropertyName">OneEquals</span> property. Normally times and durations consider DifferenceValue of 1 to be in seconds. This time it is in hours.<br/> Enter durations. To be valid, the fields must be no more than 10 hours apart.<br/><br/> Between <des:DurationTextBox ID="DurationTextBox1" runat="server" ></des:DurationTextBox> and <des:DurationTextBox ID="DurationTextBox2" runat="server" ></des:DurationTextBox> <des:DifferenceValidator ID="DifferenceValidator3" runat="server" ControlIDToEvaluate="DurationTextBox1" SecondControlIDToEvaluate="DurationTextBox2" DataType="Duration" ReportErrorsAfter="EachEdit" Operator="LessThanEqual" DifferenceValue="10" OneEquals="Hour" ErrorMessage="The fields must be no more than {DIFFERENCEVALUE} hours apart. They are currently {DIFFRESULT} apart."> <ErrorFormatterContainer> <des:TextErrorFormatter Display="Dynamic" /> </ErrorFormatterContainer> </des:DifferenceValidator> <des:DataTypeCheckValidator ID="DataTypeCheckValidator5" runat="server" ControlIDToEvaluate="DurationTextBox1" ErrorMessage="Enter a duration in DurationTextBox1."> <ErrorFormatterContainer> <des:TextErrorFormatter Display="Dynamic" /> </ErrorFormatterContainer> </des:DataTypeCheckValidator> <des:DataTypeCheckValidator ID="DataTypeCheckValidator6" runat="server" ControlIDToEvaluate="DurationTextBox2" ErrorMessage="Enter a duration in DurationTextBox2."> <ErrorFormatterContainer> <des:TextErrorFormatter Display="Dynamic" /> </ErrorFormatterContainer> </des:DataTypeCheckValidator> <br/><br/> <h2>DES Calendar</h2> The first calendar must have a selected dates at least 10 days apart.<br/> When using the <a href="../../../Menu.aspx?Topic=Calendars" class="ControlClass">Calendar</a>, the <span class="PropertyName">DifferenceValidator.DataType</span> property can be omitted.<br/><br/> <des:Calendar ID="Calendar1" runat="server" > <ClearCommand ShowField="RecommendedRow" /> </des:Calendar> <des:Calendar ID="Calendar2" runat="server"> <ClearCommand ShowField="RecommendedRow" /> </des:Calendar> <des:DifferenceValidator ID="DifferenceValidator4" runat="server" ControlIDToEvaluate="Calendar1" SecondControlIDToEvaluate="Calendar2" Operator="GreaterThanEqual" DifferenceValue="10" ErrorMessage="The fields must be at least {DIFFERENCEVALUE} days apart. They are currently {DIFFRESULT} apart."> </des:DifferenceValidator> <br/><br/> See also:<br/> <a href="../../../DateAndTime/DateTextBoxes/Validators.aspx" class="ControlClass">On DateTextBoxes</a><br/> <a href="../../../DateAndTime/TimeTextBoxes/Validators.aspx" class="ControlClass">On TimeOfDayTextBox and DurationTextBox</a><br/> <br/> <des:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click"></des:Button> 

Return to the menu   Select another DES Module