Results 1 to 6 of 6

Thread: Validating a user input

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    Connecticut
    Posts
    257

    Validating a user input

    I want to prompt the user to enter up to four specific months as an input on my page. Should I use a textbox control and just apply validators to it? or a check list box? which would control what the user puts it and would make it easier to iterate through the selected items? The only concerns I have are the looks of the list box. Can I make it look and feel like a drop down box? Also, how do I limit the selection to 4? If I use a text box, how do I validate that "up to" 4 items are entered let's say separated by a comma?

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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.
    Please mark you thread resolved using the Thread Tools as shown

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    Connecticut
    Posts
    257

    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.

  4. #4
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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>
    Please mark you thread resolved using the Thread Tools as shown

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    Connecticut
    Posts
    257

    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.

  6. #6
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    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.
    The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width