2012-10-06 30 views
5

Đây là câu hỏi đầu tiên của tôi trong stackoverflow.com.asp: RequiredFieldValidator và radiobuttons

Tôi đang làm việc trên một dự án trường học mà tôi phải xác thực thông tin nhập từ người dùng. Mỗi khi tải trang, nó cung cấp thông báo lỗi máy chủ. Vui lòng xem mã và thông báo lỗi sau.

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

Trả lời

6

Các RequiredFieldValidator không xác nhận một RadioButton. Tuy nhiên, bạn có thể sử dụng điều khiển RadioButtonList thay vào đó (được xác nhận bởi RequiredFieldValidator).

3

Các asp: RadioButton không hỗ trợ xác nhận, thay vì sử dụng một 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>