Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

WebForms UnobtrusiveValidationMode Requires a ScriptResourceMapping for jQuery

4.87/5 (22 votes)
28 Nov 2012CPOL 351.5K  
A solution to the problem

Today, while working on an ASP.NET web application in VS Express 2012 for Web, I got a strange error like this.

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

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

It was strange because I just added some basic components like TextBox, RequiredfieldValidator, and validation summary controls only. Later, I found a Microsoft Connect issue. And according to the Connect website, we can fix this by removing the following element from the web.config file.

XML
<add key="ValidationSettings:UnobtrusiveValidationMode" 
value="WebForms" />

But I couldn’t find this element in my web.config file. Another option to fix this issue is registering jQuery in Global.asax in the Application_Start event like this:

C#
ScriptManager.ScriptResourceMapping.AddDefinition("jquery", 
    new ScriptResourceDefinition
{
Path = "~/scripts/jquery-1.7.2.min.js",
DebugPath = "~/scripts/jquery-1.7.2.min.js",
CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.1.min.js",
CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.1.js"
});

And it worked without any issue. Adding the following element in web.config also works.

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

You can find more about Unobtrusive JavaScript on Wikipedia.

Happy programming!

Related Content

  1. How to access page methods from jQuery
  2. Image cropping in ASP.NET with jQuery
  3. Simple AutoSuggest Textbox using jQuery
  4. System.InvalidOperationException – The length of the string exceeds the value set on the maxJsonLength property.
  5. Pass your own arguments to the ClientValidationFunction in a CustomValidator

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)