Return to the menu   Select another DES Module

Demonstrates validators applied to the DateTextBox.

Demonstrates validators applied to the DateTextBox


Controls

These two DateTextBoxes are associated with numerous validators. Assign different dates to see how each validator responds.

Start Date:
...

End Date:
...




DataTypeCheckValidator

DataTypeCheckValidator on both textboxes (always add these validators. Do not assume client-side formatting features of the DateTextBox will protect you)

Validation not invoked yet on StartDate Validation not invoked yet on EndDate

CompareTwoFieldsValidator

CompareTwoFieldsValidator where Start Date is less than End Date

Validation not invoked yet

CompareToValueValidator

CompareToValueValidator where the date must be greater than Today.

Validation not invoked yet

RangeValidator

RangeValidator where Start Date must be between one month ago and one month from now.

Validation not invoked yet

UnselectableDatesValidator

UnselectableDatesValidator uses the SpecialDates control to identify unselectable dates. In this example, Saturdays and Sundays are unselectable.

Validation not invoked yet

DifferenceValidator

DifferenceValidator where the two dates must be more than 5 days apart.

Validation not invoked yet

RequiredTextValidator

RequiredTextValidator on Start Date

Validation not invoked yet

Source Code (C#)

<script runat="server">
protected void Page_Load(object sender, EventArgs e) { // the RangeValidator uses these two properties if assigned StartDate.MinDate = DateTime.Today.AddMonths(-1); StartDate.MaxDate = DateTime.Today.AddMonths(1); CompareToValueValidator1.ValueToCompareAsNative = DateTime.Today; } protected void Button1_Click(object sender, EventArgs e) { if (PeterBlum.DES.Globals.WebFormDirector.IsValid) { // save the data here } }
</script> <p>These two DateTextBoxes are associated with numerous validators. Assign different dates to see how each validator responds.</p> Start Date: <des:DateTextBox ID="StartDate" runat="server" SpecialDatesControlID="SpecialDates1" DateFormat="Abbreviated"> </des:DateTextBox><br/> End Date: <des:DateTextBox ID="EndDate" runat="server"> </des:DateTextBox><br/> <br/> <des:Button ID="Button1" runat="server" Text="Validation and Submit" OnClick="Button1_Click" /> <br/> <br/> <h2>DataTypeCheckValidator</h2> <a href="../../Validation/Validators/Controls/DataTypeCheckValidator.aspx" class="ControlClass">DataTypeCheckValidator</a> on both textboxes (always add these validators. Do not assume client-side formatting features of the DateTextBox will protect you)<br/><br/> <des:DataTypeCheckValidator ID="DataTypeCheckValidator1" runat="server" ControlIDToEvaluate="StartDate" ErrorMessage="Invalid entry in Start Date" NoErrorFormatter-Mode="FirstTime" NoErrorFormatter-Text="Validation not invoked yet on StartDate"> </des:DataTypeCheckValidator> <des:DataTypeCheckValidator ID="DataTypeCheckValidator2" runat="server" ControlIDToEvaluate="EndDate" ErrorMessage="Invalid entry in End Date" NoErrorFormatter-Mode="FirstTime" NoErrorFormatter-Text="Validation not invoked yet on EndDate"> </des:DataTypeCheckValidator> <br/> <br/> <h2>CompareTwoFieldsValidator</h2> <a href="../../Validation/Validators/Controls/CompareTwoFieldsValidator.aspx" class="ControlClass">CompareTwoFieldsValidator</a> where Start Date is less than End Date<br/><br/> <des:CompareTwoFieldsValidator ID="CompareTwoFieldsValidator1" runat="server" SecondControlIDToEvaluate="EndDate" ControlIDToEvaluate="StartDate" ErrorMessage="Make Start < End" Operator="LessThan" NoErrorFormatter-Mode="FirstTime" NoErrorFormatter-Text="Validation not invoked yet" > </des:CompareTwoFieldsValidator> <br/> <br/> <h2>CompareToValueValidator</h2> <a href="../../Validation/Validators/Controls/CompareToValueValidator.aspx" class="ControlClass">CompareToValueValidator</a> where the date must be greater than Today.<br/><br/> <des:CompareToValueValidator ID="CompareToValueValidator1" runat="server" ControlIDToEvaluate="StartDate" ErrorMessage="Make Start={VALUETOCOMPARE}" Operator="GreaterThan" NoErrorFormatter-Mode="FirstTime" NoErrorFormatter-Text="Validation not invoked yet"> </des:CompareToValueValidator> <br/> <br/> <h2>RangeValidator</h2> <a href="../../Validation/Validators/Controls/RangeValidator.aspx" class="ControlClass">RangeValidator</a> where Start Date must be between one month ago and one month from now.<br/><br/> <des:RangeValidator ID="RangeValidator1" runat="server" ControlIDToEvaluate="StartDate" ErrorMessage="Start Date must be between {MINIMUM} and {MAXIMUM}" NoErrorFormatter-Mode="FirstTime" NoErrorFormatter-Text="Validation not invoked yet"> </des:RangeValidator> <br/> <br/> <h2>UnselectableDatesValidator</h2> <a href="../SpecialDates/DateTextBox with unselectable dates.aspx" class="ControlClass">UnselectableDatesValidator</a> uses the SpecialDates control to identify unselectable dates. In this example, Saturdays and Sundays are unselectable.<br/><br/> <des:UnselectableDatesValidator ID="UnselectableDatesValidator1" runat="server" ControlIDToEvaluate="StartDate" ErrorMessage="Not on Sundays!" NoErrorFormatter-Mode="FirstTime" NoErrorFormatter-Text="Validation not invoked yet"> </des:UnselectableDatesValidator> <des:SpecialDates ID="SpecialDates1" runat="server"> <des:SpecialDayOfWeek DayOfWeek="Saturday" Selectable="Unselectable" ></des:SpecialDayOfWeek> <des:SpecialDayOfWeek DayOfWeek="Sunday" Selectable="Unselectable" ></des:SpecialDayOfWeek> </des:SpecialDates> <br/> <br/> <h2>DifferenceValidator</h2> <a href="../../Validation/Validators/Controls/DifferenceValidator.aspx" class="ControlClass">DifferenceValidator</a> where the two dates must be more than 5 days apart.<br/><br/> <des:DifferenceValidator ID="DifferenceValidator1" runat="server" SecondControlIDToEvaluate="EndDate" ControlIDToEvaluate="StartDate" DifferenceValue="5" ErrorMessage="More than 5 days difference" Operator="GreaterThan" NoErrorFormatter-Mode="FirstTime" NoErrorFormatter-Text="Validation not invoked yet"> </des:DifferenceValidator> <br/> <br/> <h2>RequiredTextValidator</h2> <a href="../../Validation/Validators/Controls/RequiredTextValidator.aspx" class="ControlClass">RequiredTextValidator</a> on Start Date<br/><br/> <des:RequiredTextValidator ID="RequiredTextValidator1" runat="server" ControlIDToEvaluate="StartDate" ErrorMessage="Requires an entry" NoErrorFormatter-Mode="FirstTime" NoErrorFormatter-Text="Validation not invoked yet" > </des:RequiredTextValidator>

Return to the menu   Select another DES Module