Click here to Skip to main content
15,918,889 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview on user control form, when i try to validate it it gives me this error Control '' referenced by the ControlToValidate property of '' cannot be validated

here is my code

C#
<asp:GridView ID="gvUsers" runat="server" CellPadding="4"
       AutoGenerateColumns="False" Width="100%"
      DataKeyNames="Party_Number"  AllowPaging="True" PageSize="5" OnPageIndexChanging="ChangePage" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px">
       <Columns>

           <asp:TemplateField HeaderText="PORTFOLIO">
               <ItemTemplate>
                   <%# Eval("Candidate_Portfolio") %>
               </ItemTemplate>
           </asp:TemplateField>
           <asp:ImageField DataImageUrlField="Party_Logo" HeaderText="Party Logo"
               DataImageUrlFormatString="~/Images/{0}" ItemStyle-Width="80px"
               ControlStyle-Height="50px">
               <ControlStyle Width="90px"></ControlStyle>
               <ItemStyle Width="50px" />
           </asp:ImageField>

           <asp:TemplateField HeaderText="Party Name">
               <ItemTemplate>
                   <%# Eval("Party_Name") %>
               </ItemTemplate>
           </asp:TemplateField>

           <asp:ImageField DataImageUrlField="Candidate_Image" HeaderText="Candidate Photo"
               DataImageUrlFormatString="~/Images/{0}" ItemStyle-Width="80px"
               ControlStyle-Height="50px">
               <ControlStyle Width="90px"></ControlStyle>
               <ItemStyle Width="50px" />
           </asp:ImageField>

           <asp:TemplateField HeaderText="First Name">
               <ItemTemplate>
                   <%# Eval("Candidate_First_Name") %>
               </ItemTemplate>
           </asp:TemplateField>

           <asp:TemplateField HeaderText="Last Name">
               <ItemTemplate>
                   <%# Eval("Candidate_Last_Name") %>
               </ItemTemplate>
           </asp:TemplateField>

            <asp:TemplateField HeaderText="Candi Number" Visible="false">
               <ItemTemplate>
                   <asp:HiddenField ID="HiddenField1" runat="server" value='<%# Eval("Candidate_Number") %>' />
                   <asp:Label ID="Label1" runat="server" Text='<%# Eval("Candidate_Number") %>'></asp:Label>
               </ItemTemplate>
           </asp:TemplateField>

           <asp:TemplateField HeaderText="Vote">
               <ItemTemplate>
                   <asp:RequiredFieldValidator runat="server" ID="reqVote" ControlToValidate="rdbGVRow" ErrorMessage="Please Vote for Central Portfolio" ForeColor="Red">*</asp:RequiredFieldValidator>
                   <asp:RadioButton ID="rdbGVRow" onclick="javascript:CheckOtherIsCheckedByGVID(this);" runat="server" />
               </ItemTemplate>
           </asp:TemplateField>

       </Columns>
       <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
       <HeaderStyle BackColor="#003399" Font-Bold="true" ForeColor="#CCCCFF" />
       <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
       <RowStyle BackColor="White" ForeColor="#003399" />
       <SelectedRowStyle BackColor="#009999" Font-Bold="true" ForeColor="#CCFF99" />
       <SortedAscendingCellStyle BackColor="#EDF6F6" />
       <SortedAscendingHeaderStyle BackColor="#0D4AC4" />
       <SortedDescendingCellStyle BackColor="#D6DFDF" />
       <SortedDescendingHeaderStyle BackColor="#002876" />


   </asp:GridView>
Posted
Comments
nikhil-vartak 15-Jul-13 8:30am    
RequiredFieldValidator does not work on Checkbox and RadioButton.

1 solution

Check this article on how to use CustomValidator for validating Checkbox. It will be same for RadioButton as both of them have 'checked' property.

http://dotnetprof.blogspot.in/2012/11/checkbox-list-validation-using-custom.html[^]
 
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