Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to validate radio button list by giving message(pls choose any one)if i am not choose any values.

How can i done this?

can any one give example?
Posted

Try this code:

XML
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True">
    <asp:ListItem>One</asp:ListItem>
    <asp:ListItem>Two</asp:ListItem>
    <asp:ListItem>Three</asp:ListItem>
    </asp:RadioButtonList>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
        ErrorMessage="Please Choose any value from the list"
        ControlToValidate="RadioButtonList1">*</asp:RequiredFieldValidator>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <br />
    <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
 
Share this answer
 
Haven't tried using RequiredFieldValidator on RadioButtonList as what Solution1 stated, but for a single TextBox validation, I am sure that will do it. So, I will show you the server-side validation for that:

C#
foreach(ListItem item in RadioButtonList1.Items)
{
   if(item.Selected == false)
   {
      lblValidator.Text = "Please choose an item!";
   }
}


Regards,
Eduard
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900