Webforms Unobtrusivevalidationmode Requires a Scriptresourcemapping For 'Jquery'. Please Add a Scriptresourcemapping Named Jquery(Case-Sensitive)

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

You need a web.config key to enable the pre 4.5 validation mode.

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.

Example:

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

WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Since .NET 4.5 the Validators use data-attributes and bounded Javascript to do the validation work, so .NET expects you to add a script reference for jQuery.

There are two possible ways to solve the error:


Disable UnobtrusiveValidationMode:

Add this to web.config:

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

It will work as it worked in previous .NET versions and will just add the necessary Javascript to your page to make the validators work, instead of looking for the code in your jQuery file. This is the common solution actually.


Another solution is to register the script:

In Global.asax Application_Start add mapping to your jQuery file path:

void Application_Start(object sender, EventArgs e) 
{
// Code that runs on application startup
ScriptManager.ScriptResourceMapping.AddDefinition("jquery",
new ScriptResourceDefinition
{
Path = "~/scripts/jquery-1.7.2.min.js",
DebugPath = "~/scripts/jquery-1.7.2.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"
});
}

Some details from MSDN:

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

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.

WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'

Turns out i found the solution.
You just need to write this in your C# code

protected void Page_Load(object sender, EventArgs e)
{
this.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;
}

for beginners just double click the components of your page while you are not in debugging mode double clicking a text field will direct you to the C# page.

WebForms UnobtrusiveValidationMode

you have to add this in your Web.config

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

Login Control : WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Add a ScriptResourceMapping named jquery

You can disable this new feature in web.config by changing the following key value to none like this:

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

UnobtrusiveValidationMode requires jquery ScriptResourceMapping when using ScriptBundle

That's a solution, works with Bundle and Minification, but I don't know if is the best.

bundles.Add(new ScriptBundle("~/Content/Scripts")
.Include("~/Content/jquery-1.9.0.js")
.Include("..."));

ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition { Path = "~/Content/Scripts" });

ScriptResourceDefinition.Path is the same as ScriptBundle virtual path.



Related Topics



Leave a reply



Submit