Solved

Custom validator for asp.net checkbox list

Posted on 2012-04-05
4
741 Views
Last Modified: 2012-04-16
I am using a custom validator for my radiobuttonlist, with a code simmilar to the one below, but I switched the radiobuttonlist to a checkboxlist, and seems to not work, the purpose is to check if the user selected one option that says ' other' have him enter data in the other textbox, can you please suggest how to make it work?

                 <asp:TextBox ID="txt2other" runat="server" CssClass="txtOther"></asp:TextBox>
                       &nbsp;<asp:CustomValidator ID="CustomValidator3" runat="server"
                           ClientValidationFunction="checkOther2" ControlToValidate="txt2other"
                           ErrorMessage="Please enter a comment in question #2." style="font-weight: 700"
                           ValidateEmptyText="True"></asp:CustomValidator>


        function checkOther2(oSrc, args) {
            var rbtnValue = null;
            var rbtnList = document.getElementsByName('<%= CheckBoxList1.ClientID %>');
            var radio = rbtnList[0].getElementsByTagName("input");
            for (var j = 0; j < radio.length; j++) {
                if (radio[j].checked)
                    rbtnValue = radio[j].value;
            }
            if (rbtnValue == 'Other') {
                args.IsValid = !(args.Value == "")
            }
            else {
                args.IsValid = true;
            }
        }
0
Comment
Question by:TonyReba
  • 2
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37813797
0
 
LVL 9

Author Comment

by:TonyReba
ID: 37813851
Can you check the code above and see if any error??
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37813913
controltovalidate should point to the checkboxlist rather than text box
0
 
LVL 9

Author Comment

by:TonyReba
ID: 37814049
Sorry , what I need is to validate the textbox, but is required only if

 if (rbtnValue == 'Other')  



Is selectected.....
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now