Return to the menu   Select another DES Module

Demonstrates the RequiredTextValidator

The RequiredTextValidator tests if a field’s textual value is “blank” or not. You can define what text represents “blank” such as the empty string (the default) or “Enter Text Here”. If you use the ValueWhenBlank property on a DES TextBox, the RequiredTextValidator automatically knows to consider that text as "blank".

While this validator can evaluate ListBoxes and CheckBoxes, there are better validators available.

Specify the control to evaluate with the ControlIDToEvaluate property.

The UnassignedValues property determines what text is considered unassigned. It defaults to an empty string. It allows you to define multiple strings considered unassigned, simply by separating each with a pipe (|). For example, to consider the values of an empty string and “Item1” as unassigned, enter “|Item1”. If you want those to be the only valid values, set the NotCondition property to true.


Controls

TextBox

This case applies to all DES TextBoxes, System.Web.UI.WebControls.TextBox and any subclasses.

 *

DES TextBox with ValueWhenBlank set

All DES TextBoxes offer the ValueWhenBlank property. The RequiredTextValidator knows to treat that string as if the textbox is blank.

 *

MultiSegmentDataEntry

+
-
.
+
-
.
+
-
.
+
-
 *

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>TextBox</h2> This case applies to all DES TextBoxes, System.Web.UI.WebControls.TextBox and any subclasses.<br/><br/> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <des:RequiredTextValidator ID="RequiredTextValidator1" runat="server" ControlIDToEvaluate="TextBox1" ErrorMessage="required." ShowRequiredFieldMarker="true" /> <br/> <br/> <h2>DES TextBox with ValueWhenBlank set</h2> All DES TextBoxes offer the <a href="../../../TextBoxes/Common/ValueWhenBlank.aspx" class="PropertyName">ValueWhenBlank</a> property. The RequiredTextValidator knows to treat that string as if the textbox is blank.<br/><br/> <des:TextBox ID="TextBox2" runat="server" ValueWhenBlank="Fill me in"></des:TextBox> <des:RequiredTextValidator ID="RequiredTextValidator3" runat="server" ControlIDToEvaluate="TextBox2" ErrorMessage="required." ShowRequiredFieldMarker="true" /> <br/> <br/> <h2>MultiSegmentDataEntry</h2> <des:MultiSegmentDataEntry ID="MultiSegmentDataEntry1" runat="server"> <Segments> <des:IntegerTextSegment MinLength="1" MaxLength="3" CssClass="DESTBMultiSegTextBox" ShowSpinner="True" FormattingTextAfter="." /> <des:IntegerTextSegment MinLength="1" MaxLength="3" CssClass="DESTBMultiSegTextBox" ShowSpinner="True" FormattingTextAfter="." /> <des:IntegerTextSegment MinLength="1" MaxLength="3" CssClass="DESTBMultiSegTextBox" ShowSpinner="True" FormattingTextAfter="." /> <des:IntegerTextSegment MinLength="1" MaxLength="3" CssClass="DESTBMultiSegTextBox" ShowSpinner="True" /> </Segments> </des:MultiSegmentDataEntry> <des:RequiredTextValidator ID="RequiredTextValidator2" runat="server" ControlIDToEvaluate="MultiSegmentDataEntry1" ErrorMessage="required" ShowRequiredFieldMarker="true" > </des:RequiredTextValidator> <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