Return to the menu   Select another DES Module

Demonstrates the DuplicateEntryValidator

The DuplicateEntryValidator evaluates three or more data entry controls to determine if there are any duplicate entries. You can compare textual values in any of the controls supported: TextBox, ListBox, and DropDownList. For ListBox and DropDownList, the textual value is the Value property associated with selected item. If you are only using ListBoxes or DropDownLists, you can compare the selected indexes to confirm that there are no duplicates.

Specify the data entry controls within the ControlsToMatch property. It is a collection that holds PeterBlum.DES.Web.WebControl.LabeledControl objects, where you identify the control and optionally its label.

Use the MatchMode property to specify a rule for matching: exact match, case insensitive match, or use the SelectedIndex property (only for ListBox and DropDropList controls).

Use the IgnoreUnassigned property to ignore blank controls.

The label is used in the ErrorMessage and SummaryErrorMessage properties when you include the tokens “{LABEL1}” and “{LABEL2}”. They help lead the user to a pair of fields found with duplicate values. Your ErrorMessage can also contain the token “{TEXTVALUE}” to show the value found to be duplicated.


Controls

Compare 4 TextBoxes

Enter duplicate values in any textboxes.

Name1
Name2
Name3
Name4


Compare SelectedIndex values in DropDownLists

Assign identical selections in two or more DropDownLists




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>Compare 4 TextBoxes</h2> Enter duplicate values in any textboxes.<br/><br/> <asp:Label ID="Label1" runat="server" Text="Name1" /><asp:TextBox ID="TextBox1" runat="server" /><br/> <asp:Label ID="Label2" runat="server" Text="Name2" /><asp:TextBox ID="TextBox2" runat="server" /><br/> <asp:Label ID="Label3" runat="server" Text="Name3" /><asp:TextBox ID="TextBox3" runat="server" /><br/> <asp:Label ID="Label4" runat="server" Text="Name4" /><asp:TextBox ID="TextBox4" runat="server" /><br/> <des:DuplicateEntryValidator id=DuplicateEntryValidator1 runat="server" IgnoreBlankText="True" MatchMode="CaseInsensitive" ErrorMessage='The value "{TEXTVALUE}" is shown in both {LABEL1} and {LABEL2}. Only unique values are accepted.'> <ControlsToMatch> <des:LabeledControl ControlID="TextBox1" Label-LabelControlID="Label1" /> <des:LabeledControl ControlID="TextBox2" Label-LabelControlID="Label2" /> <des:LabeledControl ControlID="TextBox3" Label-Text="Name3" /> <des:LabeledControl ControlID="TextBox4" Label-Text="Name4" /> </ControlsToMatch> </des:DuplicateEntryValidator> <br/> <br/> <h2>Compare SelectedIndex values in DropDownLists</h2> Assign identical selections in two or more DropDownLists<br/><br/> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="DropDownList3" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:DropDownList> <des:DuplicateEntryValidator ID="DuplicateEntryValidator2" runat="server" ErrorMessage="They can't match" MatchMode=SelectedIndex > <ControlsToMatch> <des:LabeledControl ControlID="DropDownList1" /> <des:LabeledControl ControlID="DropDownList2" /> <des:LabeledControl ControlID="DropDownList3" /> </ControlsToMatch> <ErrorFormatterContainer> <des:TextErrorFormatter/> </ErrorFormatterContainer> </des:DuplicateEntryValidator> <br/><br/> <des:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click"></des:Button>

Return to the menu   Select another DES Module