Return to the menu   Select another DES Module

Demonstrates the ListSizeValidator

The ListSizeValidator evaluates a listbox or dropdownlist to determine if has enough elements listed. It is used when the user interface allows adding and removing elements to a list.

Specify the ListBox to evaluate with the ControlIDToEvaluate property.

By default, it requires at least one item in the list. Set a different minimum with the Minimum property and introduce a maximum with the Maximum property.

The ErrorMessage and SummaryErrorMessage properties support several tokens:

  • "{MINIMUM}" – The value of the Minimum property.
  • "{MAXIMUM}" – The value of the Maximum property.
  • "{COUNT}" – The number of items in the list.
  • "{COUNT:singular:plural}" – Shows either the word in the “singular” position or “plural” position based on the count. Singular is shown if the count is 1.


Controls

ListBox 1 allows a maximum of 4.
ListBox 2 allows between 2 and 3.


Listbox 1 Errors:
ListBox 2 Errors:

Source Code (C#)

<script runat="server">
protected void Button1_Click(object sender, EventArgs e) { if (PeterBlum.DES.Globals.WebFormDirector.IsValid) { // save your data here } } protected void MoveAtoB_Click(object sender, EventArgs e) { Transfer(ListBoxA, ListBoxB); } protected void MoveBtoA_Click(object sender, EventArgs e) { Transfer(ListBoxB, ListBoxA); } protected void Transfer(ListBox pSourceList, ListBox pDestList) { if (pSourceList.SelectedItem != null) { ListItem vItem = pSourceList.SelectedItem; vItem.Selected = false; pDestList.Items.Add(vItem); pSourceList.Items.Remove(vItem); } }
</script> ListBox 1 allows a maximum of 4.<br/> ListBox 2 allows between 2 and 3.<br/><br/> <asp:ListBox ID="ListBoxA" runat="server" Height="100px" Width="50px"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:ListBox> <asp:Button ID="MoveAtoB" runat="server" CausesValidation="False" OnClick="MoveAtoB_Click" Text="Move >>" /> <asp:Button ID="MoveBtoA" runat="server" CausesValidation="False" OnClick="MoveBtoA_Click" Text="<< Move" /> <asp:ListBox ID="ListBoxB" runat="server" Height="100px" Width="50px"> <asp:ListItem>4</asp:ListItem> <asp:ListItem>5</asp:ListItem> <asp:ListItem>6</asp:ListItem> </asp:ListBox> <br/> Listbox 1 Errors: <des:ListSizeValidator ID="ListSizeValidator1" runat="server" ControlIDToEvaluate="ListBoxA" ErrorMessage="Maximum of {MAXIMUM}. You have {COUNT} {COUNT:item:items}." Maximum="4" Minimum="0"> <ErrorFormatterContainer> <des:TextErrorFormatter/> </ErrorFormatterContainer> </des:ListSizeValidator> <br/> ListBox 2 Errors:<des:ListSizeValidator ID="Listsizevalidator2" runat="server" ControlIDToEvaluate="ListBoxB" ErrorMessage="Between {MINIMUM} and {MAXIMUM}. You have {COUNT} {COUNT:item:items}." Maximum="3" Minimum="2"> <ErrorFormatterContainer> <des:TextErrorFormatter/> </ErrorFormatterContainer> </des:ListSizeValidator> <br/> <des:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click"></des:Button>

Return to the menu   Select another DES Module