Results 1 to 6 of 6

Thread: How to validate checkboxes and radiolist in ASP.NET

  1. #1
    Join Date
    Oct 2010
    Posts
    55

    How to validate checkboxes and radiolist in ASP.NET

    I have just joined a course for learning an ASP.NET in the university. Its me early stages and I have created one form by using this programming language. This form has couple of checkboxes and radiolists along with some text boxes and labels. Now its time to validate these items about which I have no idea how to do it. Can you guys tell me that how can I validate checkboxes and radiolist in ASP.NET?

  2. #2
    Join Date
    Apr 2009
    Posts
    569

    Re: How to validate checkboxes and radiolist in ASP.NET

    I recently had the requirement to validate a CheckBoxList Control. Come with the ASP.NET validators that can be to not do anything other than the cashing of an exception. This is a good thing, because they are not meant for it. There are basically three ways how this problem can be solved:
    • CustomValidator write for conducting the review
    • Check manually in code
    • Self Validator create that derives from BaseValidator

  3. #3
    Join Date
    May 2009
    Posts
    511

    Re: How to validate checkboxes and radiolist in ASP.NET

    According to me Option 1 is the best, especially when it comes to reuse. I implemented a relatively simple but effective validator, it works at the moment purely server-side. Client-side validation could still be implemented in addition. There are three properties and two of them can be combined:
    1. MinChecked (There must be at least as many options are selected)
    2. MaxChecked (A maximum of as many optoins be marked)
    3. MinChecked MaxChecked and combined (minimum and maximum)
    4. EqualsChecked (Just as many entries must be marked)


    If BaseValidator or another of them inherits the Validator, is derived, which has the advantage that the use of a custom validator controls tying in seamlessly with the use of the existing one.

  4. #4
    Join Date
    May 2009
    Posts
    637

    Re: How to validate checkboxes and radiolist in ASP.NET

    I had a couple of asp projects in my first year and I used to validate the checkboxelist in the following way. The following code is sufficient to validate a CheckBoxList in such a way that exactly two entries must be chosen so that the control is valid:
    Code:
    < asp:CheckBoxList ID ="chkListTest" runat ="server" > 
    < asp:ListItem Text ="Eintrag Eins" /> 
    < asp:ListItem Text ="Eintrag Zwei" /> 
    </ asp:CheckBoxList > 
    < t4m:CheckBoxListValidator 
    ID ="valGeschlecht" 
    ControlToValidate ="chkListTest" 
    ErrorMessage ="Bitte genau zwei Optionen auswählen" 
    EqualsChecked ="2" 
    runat ="server" />

  5. #5
    Join Date
    May 2009
    Posts
    539

    Re: How to validate checkboxes and radiolist in ASP.NET

    The RequiredFieldValidator checks if the assigned Control from the client either completed or whether the client has made a selection from the given control. When used with an ASP.NET textbox control but we will not review the appropriateness of user input, but just as the name suggests, is only checked if she was ever completed by the client. Complex tasks can be accomplished by combinations of the control.

    Code:
    ...
      <tr>
           <td align=left> Name: </ td>
           <td>
             <asp:TextBox id=txtName runat="server" />
           </ Td>
           <td>
             <Asp: RequiredFieldValidator id = "ReqFName" runat = "server"
                 ControlToValidate = "txtName" 
                 ErrorMessage = "Please enter Name">
             </ Asp: RequiredFieldValidator>
           </ Td>
      </ Tr>
      ...
    To facilitate the positioning of the text and input fields, I have embedded the ASP.NET Contols in a common HTML Table. In the above block of code checks if the (s) a in the text box with id "txtName" entered the names users. This is done using the RequiredFieldValidator with ID "ReqFName. The attribute ControlToValidate references the textbox control, so that control to be checked. Error message indicates the error message to be output.

  6. #6
    Join Date
    Apr 2009
    Posts
    488

    Re: How to validate checkboxes and radiolist in ASP.NET

    RegularExpressionValidator : This validator compares the user input with a given regular expression. Will use this example for the validity check of phone numbers or postal codes. For example, here is a string to be checked, the only capital letter and can contain six characters long.
    Code:
     <Asp: RegularExpressionValidator id = "RegExVal" runat = "server"
                 ControlToValidate = "txtBox1"
                 ValidationExpression = "[AZ] {6}"
                 Display = "Static"
                 ErrorMessage = "String is invalid">
             </ Asp: RegularExpressionValidator>
    The validation attribute specifies the regular expression expression. This sets the conditions for capital letters ([az]) and for a string of 6 characters ({6})

Similar Threads

  1. How to check all the checkboxes by using JavaScript?
    By Dhano in forum Software Development
    Replies: 6
    Last Post: 12-04-2012, 02:49 AM
  2. Checkboxes Icons on Vista Desktop
    By Nazmin in forum Customize Desktop
    Replies: 3
    Last Post: 25-04-2011, 05:39 AM
  3. Can we get checkboxes in XP like Windows Vista
    By Michael Sabin in forum Customize Desktop
    Replies: 6
    Last Post: 24-09-2009, 05:46 PM
  4. How to create .Net custom checkboxes for listview
    By Rover in forum Software Development
    Replies: 2
    Last Post: 11-06-2009, 09:40 AM
  5. How to set sessions for checkboxes
    By RogerFielden in forum Software Development
    Replies: 3
    Last Post: 15-04-2009, 02:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,911,729.87844 seconds with 17 queries