Solved

How to apply validation control in asp:radio button list

Posted on 2014-04-22
3
501 Views
Last Modified: 2014-05-09
I have the asp:radiobuttons
How to apply required validation control in such a way that the users access atleast one.

 <asp:RadioButtonList ID="RBL_mode" runat="server" AutoPostBack="True"
                            CssClass="report_color" onselectedindexchanged="RBL_mode_SelectedIndexChanged"
                            RepeatDirection="Horizontal" Width="674px">
                            <asp:ListItem Value="1" Selected="False">Monovalent RDT</asp:ListItem>
                             <asp:ListItem Value="11" Selected="False">Monovalent RDT+Slide</asp:ListItem>
                            <asp:ListItem Value="2" Selected="False">Bivalent RDT</asp:ListItem>
                             <asp:ListItem Value="22" Selected="False">Bivalent RDT+Slide</asp:ListItem>
                            <asp:ListItem Value="3" Selected="False">Referral</asp:ListItem>
                            <asp:ListItem Value="0" Selected="False">Slide only</asp:ListItem>
                        </asp:RadioButtonList>
0
Comment
Question by:searchsanjaysharma
3 Comments
 
LVL 5

Accepted Solution

by:
jayakrishnabh earned 250 total points
ID: 40016815
<asp:RadioButtonList ID="RBL_mode" runat="server" AutoPostBack="True" onselectedindexchanged="RBL_mode_SelectedIndexChanged"
                            CssClass="report_color" RepeatDirection="Horizontal" Width="674px">
                            <asp:ListItem Value="1" Selected="False">Monovalent RDT</asp:ListItem>
                             <asp:ListItem Value="11" Selected="False">Monovalent RDT+Slide</asp:ListItem>
                            <asp:ListItem Value="2" Selected="False">Bivalent RDT</asp:ListItem>
                             <asp:ListItem Value="22" Selected="False">Bivalent RDT+Slide</asp:ListItem>
                            <asp:ListItem Value="3" Selected="False">Referral</asp:ListItem>
                            <asp:ListItem Value="0" Selected="False">Slide only</asp:ListItem>
                        </asp:RadioButtonList>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="RBL_mode" Enabled="true"
             ValidationGroup="ValidationGroup1"></asp:RequiredFieldValidator>
        <asp:Button ID="Button1" runat="server" Text="Button" CausesValidation="true" ValidationGroup="ValidationGroup1" />
0
 
LVL 12

Assisted Solution

by:duttcom
duttcom earned 250 total points
ID: 40016828
A RequiredFieldValidator for your list would look something like this-

<asp:RequiredFieldValidator runat="server" ErrorMessage="You must select at least one option!!!" ID="RBL_mode_validator" ControlToValidate="RBL_mode">
                </asp:RequiredFieldValidator>

This is a simple validator that will assume a starting value for the radiobuttonlist is null and requires that the value of the list changes in order for it to be valid. So this will work well for entering records for the first time, but not as well if you are editing records which already have a value (in which case you will need to do a custom validator with code to check that an option has been selected in the list).
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 40053310
tx
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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