Solved

How to apply validation control in asp:radio button list

Posted on 2014-04-22
3
496 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
rest webservice call over https via c# 6 37
Web Form VB.Net  import CSV 4 36
Example works but why do I need to click twice on button 4 36
C# Gridview 1 29
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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 …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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