Rahul Gokani
Rahul Gokani

Reputation: 1708

RequiredFieldValidator is not working in GridView with VS2012

I am developing a SharePoint 2013's Provider Hosted App. In that I have an .aspx Page. In that page I am using GridView for Textboxes only.
It was working fine but when I put the RequiredFieldValidator inside GridView I got an Error.
GridView Code:

<asp:GridView ID="gv_ans_list" runat="server" AutoGenerateColumns="false">
    <Columns>
         <asp:TemplateField HeaderStyle-CssClass="head">
             <ItemTemplate>
                 <asp:TextBox ID="txt_ans" runat="server" Text='<%#Bind("answer") %>'></asp:TextBox>
                 <asp:RequiredFieldValidator ID="Req1" runat="server" ControlToValidate="txt_ans" ValidationGroup="v1" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
             </ItemTemplate>
             <FooterTemplate>
                 <asp:TextBox ID="txt_ans_foot" runat="server"></asp:TextBox>
             </FooterTemplate>
         </asp:TemplateField>
         <asp:CommandField ShowDeleteButton="true" ButtonType="Image" DeleteImageUrl="~/Images/delete.png" />
    </Columns>
</asp:GridView>

<asp:LinkButton ID="lnk_add" runat="server" Text="Add more Answers" OnClick="lnk_add_Click" ValidationGroup="v1"></asp:LinkButton>

Error:
This is the error

When I put the RequiredFieldValidator only then i am getting this error.
Please help me to solve this.

Upvotes: 0

Views: 1505

Answers (1)

Kapil Khandelwal
Kapil Khandelwal

Reputation: 16144

Try:

<appSettings>
  <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>

More Info on ValidationSettings:UnobtrusiveValidationMode

Specifies how ASP.NET globally enables the built-in validator controls to use unobtrusive JavaScript for client-side validation logic.

Type: UnobtrusiveValidationMode

Default value: None

Remarks: If this key value is set to "None" [default], the ASP.NET application will use the pre-4.5 behavior (JavaScript inline in the pages) for client-side validation logic. If this key value is set to "WebForms", ASP.NET uses HTML5 data-attributes and late bound JavaScript from an added script reference for client-side validation logic.

Upvotes: 2

Related Questions