Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp:RequiredFieldValidator and radiobuttons

This is my first question in stackoverflow.com.

I am working on a school project which I have to validate the input from the user. Everytime the page load, it give the server error message. Please see the codes, and the error message after.

<div>
<table>
<td>
<asp:RadioButton ID="RadioButton1" runat="server"></asp:RadioButton>
<asp:RequiredFieldValidator ID="validateCheck" runat="server"  ControlToValidate="RadioButton1"   ErrorMessage="Please Enter" Display="Dynamic"></asp:RequiredFieldValidator>             
</td>
</table>
</div>

Server Error in '/' Application.
Control 'RadioButton1' referenced by the ControlToValidate property of 'validateCheck' cannot be validated.
like image 563
user1725732 Avatar asked Oct 06 '12 23:10

user1725732


2 Answers

The RequiredFieldValidator does not validate a RadioButton. However, you can use the RadioButtonList control instead (validated by RequiredFieldValidator).

like image 134
Mateus Schneiders Avatar answered Nov 09 '22 16:11

Mateus Schneiders


The asp:RadioButton do not support validation, instead of RadioButton use a RadioButtonList:'

    <form id="form1" runat="server">
<div>

    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
        ErrorMessage="RequiredFieldValidator" ControlToValidate="RadioButtonList1"></asp:RequiredFieldValidator>

</div>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />

<asp:RadioButtonList ID="RadioButtonList1" runat="server">
    <asp:ListItem>One</asp:ListItem>
    <asp:ListItem>Two</asp:ListItem>
</asp:RadioButtonList>

</form>
like image 30
Armando Peña Avatar answered Nov 09 '22 15:11

Armando Peña