?
Solved

Custom validator for asp.net checkbox list

Posted on 2012-04-05
4
Medium Priority
?
754 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 1500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

800 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