Solved

How to apply validation control in asp:radio button list

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

624 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