Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7441647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:02:57+00:00 2026-05-29T11:02:57+00:00

Before I start I’d just like to state that the code created by ASP.NET

  • 0

Before I start I’d just like to state that the code created by ASP.NET for CheckBoxLists is probably the worst thing I’ve ever seen.

Anyway,

I am using the jQuery validation plugin to validate my ASP.net form. There is a requirement to validate some checkboxes. These are generated by a CheckBoxList control.

<asp:CheckBoxList ID="CBContext" runat="server" RepeatColumns="2" 
              DataSourceID="sqlLibraryEnquiries" DataTextField="value" DataValueField="value" name="topic">
</asp:CheckBoxList>

This control produces the following abomination of xHTML

<table id="MainContent_CBContext" name="topic">
    <tr>
        <td>
          <input id="MainContent_CBContext_0" type="checkbox" name="ctl00$MainContent$CBContext$0" value="Business" /><label for="MainContent_CBContext_0">Business</label>
        </td>
        <td>
          <input id="MainContent_CBContext_2" type="checkbox" name="ctl00$MainContent$CBContext$2" value="Legal" /><label for="MainContent_CBContext_2">Legal</label>
        </td>
    </tr>
    <tr>
        <td>
           <input id="MainContent_CBContext_1" type="checkbox" name="ctl00$MainContent$CBContext$1" value="Business Development" /><label for="MainContent_CBContext_1">Business Development</label>
        </td>
        <td>
           <input id="MainContent_CBContext_3" type="checkbox" name="ctl00$MainContent$CBContext$3" value="Library" /><label for="MainContent_CBContext_3">Library</label>
        </td>
    </tr>
</table>

The issue I am having is actually getting the jQuery Validator plugin to hook into the checkbox list. In my rules section for all the other fields I can get to them with their names
for example ctl00$MainContent$tbActions: but the checkboxes all have different names.

The cb_selectone rule isn’t firing because the object I am trying to validate is never found.
I have tried the following identifiers. CBContext, ctl00$MainContent$CBContext, MainContent_CBContext and checkboxes.

$("#Form1").validate({

     rules: {
     //WHAT GOES HERE???? --------->>    CBContext or ctl00$MainContent$CBContext or MainContent_CBContext or checkboxes all don't work: {
            cb_selectone: true
         }
      }
});

Thanks for your help.

SM

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:02:57+00:00Added an answer on May 29, 2026 at 11:02 am

    Ok I Solved it……

    What I did was create a new validator method that gets all the objects of type input that match a regex of MainContent_CBContext. This returns an array of all the checkboxes.

    Then loop round the array and check if the attr is checked. If any of them are then set the return as true.

    $.validator.addMethod('cb_selectone', function (value, element) {
         if (debug) {
             $.jGrowl("Adding Validation");
         }
         var chkGroup = $("input[id^=MainContent_CBContext]");
         if (chkGroup.length > 0) {
             for (var i = 0; i < chkGroup.length; i++) {
                 if ($(chkGroup[i]).attr('checked')) {
                     if (debug) {
                        // alert(i + $(chkGroup[i]).val());
                         $.jGrowl("Running loop " + i + " = " + $(chkGroup[i]).val());
                     }
                     return true;
                 }
             }
             return false;
         }
         return false;
     }, 'Please select at least one option');
    

    The part I was stuck on was finding an object to fire off the addMethod code.
    In the end I just used…

    ctl00$MainContent$CBContext$2: {
       cb_selectone: true
    }
    

    This meant that the label is placed next to this field, it’s purely cosmetic. The important thing is the validator code was finally bound to a real object and fired correctly.

    SM

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before I start with the real question, let me just say that I might
Before start let me tell my experience: I am experienced with C#.NET, web services,
Before you start flaming, I'm going to tell you that I am trying to
Before I start, I want to point out that I'm pretty sure this actually
Am just started working for exporting excel spread sheet in PERL, Before start i
Before I start I must say that I maybe biting more than I can
I want to get one record before start date and end date DtpFrom means
I usually try to do TDD with not much analysis (no diagrams) before start
Before I start, I know there is this post and it doesn't answer my
Before you start firing at me, I'm NOT looking to do this, but someone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.