2012-10-06 9 views
5

これは私の最初の質問stackoverflow.comです。asp:RequiredFieldValidatorとラジオボタン

私はユーザーからの入力を検証する必要がある学校プロジェクトに取り組んでいます。ページが読み込まれるたびに、サーバーにエラーメッセージが表示されます。コードを参照してください。その後にエラーメッセージが表示されます。

<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. 

答えて

6

のRequiredFieldValidatorは、ラジオボタンを検証しません。ただし、代わりにRadioButtonListコントロールを使用することができます(RequiredFieldValidatorによって検証されます)。

3

ASP:RadioButtonコントロールが検証をサポートしていない、代わりのRadioButtonの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> 
関連する問題