Error: WebForms UnobtrusiveValidationMode Requires a ScriptResourceMapping For jQuery in .Net

Error : WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery. Please add a ScriptResourceMapping named jquery(case-sensitive).

This article explains that how can remove an error that is title of article in .Net Framework 4.5. This error comes when you used the RequiredFieldValidator control on any other server control. Let’s see with an example.

Create Web Form

You need to create a web form that has one textbox for user input and a button. The TextBox control has a required field validator control.

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ValidationApplication.Default" %>  
  2.   
  3. <!DOCTYPE html>  
  4. <html xmlns="http://www.w3.org/1999/xhtml">  
  5. <head id="Head1" runat="server">  
  6.     <title>Required Field example</title>  
  7. </head>  
  8. <body>  
  9.     <form id="form1" runat="server">  
  10.     <div>  
  11.         Name :  
  12.         <asp:TextBox ID="txtName" runat="server"></asp:TextBox>  
  13.         <asp:RequiredFieldValidator ID="reqName" runat="server" Display="Dynamic" ControlToValidate="txtName"  
  14.             Text="Name is empty" Style="color: red"></asp:RequiredFieldValidator>  
  15.         <asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClick="btnSubmit_Click" />  
  16.     </div>  
  17.     </form>  
  18. </body>  
  19. </html> 

Server Side Code

You need to create a click event of button that shows input values.  

  1. using System;    
  2.     
  3. using System.Web.UI;    
  4. namespace ValidationApplication    
  5.     
  6. {    
  7.     public partial class Default : System.Web.UI.Page    
  8.     {    
  9.         protected void Page_Load(object sender, EventArgs e)    
  10.         {     
  11.         }    
  12.         protected void btnSubmit_Click(object sender, EventArgs e)    
  13.         {    
  14.             if (Page.IsValid)    
  15.             {    
  16.                 Response.Write("My name is :" + txtName.Text);    
  17.             }    
  18.         }    
  19.     }    
  20. } 

Run the Application

Now run the application and leave input field blank and click on submit button. You get below error message as figure 1.1.

Error Message After submit button click
Figure 1.1 : Error Message After submit button click

Resolve Error

Now add key for Unobtrusive under <appSettings> tag as following code.
  1. <?xml version="1.0"?>  
  2. <configuration>  
  3.     <system.web>  
  4.       <compilation debug="true" targetFramework="4.5" />  
  5.       <httpRuntime targetFramework="4.5" />  
  6.     </system.web>  
  7.   <appSettings>  
  8.     <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />  
  9.   </appSettings>  
  10. </configuration> 

Validation Message

After that again run the application leave blank input field and click on submit button the you get a validation message as figure 1.2

Validation message
Figure 1.2 Validation message

Now insert value in input field and run the application. You get result as figure 1.3.

Successful submits data
Figure 1.3 Successful submits data