Solved

Custom validator for asp.net checkbox list

Posted on 2012-04-05
4
744 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

Suggested Solutions

Title # Comments Views Activity
Web site error 3 41
Service Controller 1 23
asp.net mvc5 6 16
What Does This C# Code Block Do? 5 30
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 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