Re: Validating a user input
If there only four months then you should consider using ListBox or CheckBox, and in ListBox Multiselect Option must be enabled. If you are really concerned about the height of the Listbox then go for the CheckBox in Horizontal manner. Text Box will be tedious as the user has to enter values separated by comma. And for the restriction either you can do this by Server Side using ListBox.SelectedItems.Count Method or in Client Side using either Jquery or JS.
Re: Validating a user input
Thank you for that info. Do you happen to know the java script I need to use to do the client side validation if I wanted only up to 4 selections? Also, I changed my listbox to multiple as the property value for the selectionmode, but it still only shows one selection at a time. Any ideas on that? What's weird is if I go to the collection and change their selected property to true for a couple of them, it shows multiple selections when I load the page, but then reverts to single selection as soon as I click on one.
Re: Validating a user input
Where did you set the Selection Mode?
The sample code
Code:
<asp:ListBox id="ListBox1"
Rows="6"
Width="100px"
SelectionMode="Multiple"
runat="server">
<asp:ListItem Selected="True">Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</asp:ListBox>
Re: Validating a user input
I set it in the properties window, but here's what the source code looks like:
Code:
<asp:ListBox ID="MonthsListBox" runat="server" Height="25px" Width="143px" Rows="12" SelectionMode="Multiple">
<asp:ListItem Selected="True">January</asp:ListItem>
<asp:ListItem>February</asp:ListItem>
<asp:ListItem>March</asp:ListItem>
<asp:ListItem>April</asp:ListItem>
<asp:ListItem>May</asp:ListItem>
<asp:ListItem Selected="True">June</asp:ListItem>
<asp:ListItem>July</asp:ListItem>
<asp:ListItem>August</asp:ListItem>
<asp:ListItem>September</asp:ListItem>
<asp:ListItem>October</asp:ListItem>
<asp:ListItem>November</asp:ListItem>
<asp:ListItem>December</asp:ListItem>
</asp:ListBox>
As you can see I selected two items just to check if the multi-select was working and it does when the page loads, but as soon as I select something else, it changes to single select. Even if I don't set the selected = "true" on both those, then run the page, it starts out with nothing selected and operates as single select. Crazy, I know. Feels like it's a bug. When I run the page this is what I get in the page source code:
Code:
<td colspan="2">
<select size="12" name="MonthsListBox" multiple="multiple" id="MonthsListBox" style="height:25px;width:143px;">
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select></td>
And it operates as single select.
Re: Validating a user input
For browsers multipul select you need to hold ctrl and click.... that's for IE and I think it varies for Mac OS. Maybe checkboxes is a more user friendly approach.