The DataTypeCheckValidator tests a field’s textual value conforms to the format
a particular data type. DES includes an extensive and expandable list of data types.
Specify the control to evaluate with the ControlIDToEvaluate property.
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.
Data types like date and currency will follow culture specific formatting set on
the current web page or overridden on PeterBlum.DES.Globals.WebFormDirector.CultureInfo.
If you are get a value from a textbox by retrieving a string from the TextBox.Text
property, let this validator assist you in converting that string to its native
type, such as Integer or DateTime, with the ControlToNative() method.
Any of DES's data type entry textboxes (integer, decimal, date, etc) do not
require setting the
property.
Enter an integer. Since IntegerTextBox filters out illegal keystrokes,
use the Paste command to insert some invalid text.
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
if (PeterBlum.DES.Globals.WebFormDirector.IsValid)
{
}
}
</script>
<h2>Textbox used for integer entry</h2>
Enter an integer.<br/><br/>
<des:TextBox ID="TextBox1" runat="server" ></des:TextBox>
<des:DataTypeCheckValidator ID="DataTypeCheckValidator1" runat="server"
ControlIDToEvaluate="TextBox1" DataType="Integer"
ErrorMessage="Enter an integer." />
<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 an integer. Since IntegerTextBox filters out illegal keystrokes,
use the Paste command to insert some invalid text.<br/><br/>
<des:IntegerTextBox ID="IntegerTextBox1" runat="server" ></des:IntegerTextBox>
<des:DataTypeCheckValidator ID="DataTypeCheckValidator2" runat="server"
ControlIDToEvaluate="IntegerTextBox1"
ErrorMessage="Enter an integer." />
<br/>
<br/>
<h2>MultiSegmentDataEntry as a Date</h2>
<br/>
<des:MultiSegmentDataEntry id="MultiSegmentDataEntry1" runat="server" >
<Segments>
<des:DropDownListSegment CssClass="DESTBMultiSegDropDownList"
FormattingTextAfter="/" >
<Items>
<asp:ListItem Value="1">Jan</asp:ListItem>
<asp:ListItem Value="2">Feb</asp:ListItem>
<asp:ListItem Value="3">Mar</asp:ListItem>
<asp:ListItem Value="4">Apr</asp:ListItem>
<asp:ListItem Value="5">May</asp:ListItem>
<asp:ListItem Value="6">Jun</asp:ListItem>
<asp:ListItem Value="7">Jul</asp:ListItem>
<asp:ListItem Value="8">Aug</asp:ListItem>
<asp:ListItem Value="9">Sep</asp:ListItem>
<asp:ListItem Value="10">Oct</asp:ListItem>
<asp:ListItem Value="11">Nov</asp:ListItem>
<asp:ListItem Value="12">Dec</asp:ListItem>
</Items>
</des:DropDownListSegment>
<des:IntegerTextSegment MinLength="1" MaxLength="2"
CssClass="DESTBMultiSegTextBox" ShowSpinner="True" Required="False"
FormattingTextAfter="/" />
<des:DropDownListSegment CssClass="DESTBMultiSegDropDownList" >
<Items>
<asp:ListItem Value="2006">2006</asp:ListItem>
<asp:ListItem Value="2007">2007</asp:ListItem>
<asp:ListItem Value="2008">2008</asp:ListItem>
<asp:ListItem Value="2009">2009</asp:ListItem>
<asp:ListItem Value="2010">2010</asp:ListItem>
<asp:ListItem Value="2011">2011</asp:ListItem>
<asp:ListItem Value="2012">2012</asp:ListItem>
<asp:ListItem Value="2013">2013</asp:ListItem>
<asp:ListItem Value="2014">2014</asp:ListItem>
<asp:ListItem Value="2015">2015</asp:ListItem>
</Items>
</des:DropDownListSegment>
</Segments>
</des:MultiSegmentDataEntry>
<des:DataTypeCheckValidator ID="DataTypeCheckValidator3" runat="server" DataType="Date"
ControlIDToEvaluate="MultiSegmentDataEntry1" ErrorMessage="That is not a legal date. " />
<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="Validate and Submit" OnClick="Button1_Click" />