web analytics

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

Options

codeling 1599 - 6654
@2016-01-05 14:41:49

I add RequiredFieldValidator control in my ASP.NET WebForm page to ensure TextBox named "TextBox1" has value.

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" Display="Dynamic" onser SetFocusOnError="True" ErrorMessage="This is a mandatory field." />

The following runtime error is captured after I compile and run the application:

WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive). Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).] System.Web.UI.ClientScriptManager.EnsureJqueryRegistered() +2287470 System.Web.UI.WebControls.BaseValidator.RegisterUnobtrusiveScript() +10 System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +9830941 System.Web.UI.Control.PreRenderRecursiveInternal() +83 System.Web.UI.Control.PreRenderRecursiveInternal() +155 System.Web.UI.Control.PreRenderRecursiveInternal() +155 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974

@2016-01-05 15:01:09

Solution 1

Unobtrusive validation is enabled by default in new version of ASP.NET. Unobtrusive validation aims to decrease the page size by replacing the inline JavaScript for performing validation with a small JavaScript library that uses jQuery.

You can bring in jquery and jqueryUI libraries by modifying the Application_Start method in global.asax:

using System.Web.UI;

......

protected void Application_Start(object sender, EventArgs e)

{

        string JQueryVer = "2.1.4";

        ScriptManager.ScriptResourceMapping.AddDefinition("jquery",

               new ScriptResourceDefinition

               {

                    Path = "~/Scripts/jquery-" + JQueryVer + ".min.js",

               }

          );

}

You can downlonad the jQuery libraries by using NuGet Package Manager in Visual Studio:

1. Right click you Web application project, and choose Manage NuGet Package...

2. Type "jQuery" to search latest version of jQuery libriaries and download the libraries to your project.

@2016-01-05 15:09:18

Solution 2

you can disable the use of unobtrusive JavaScript for client-side validation by adding the following to the web.config file:

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

 

UnobtrusiveValidationMode

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

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.

@2016-01-05 15:11:53

Solution 3

You can also disable the functionality on a per page basis by setting the Page.UnobtrusiveValidationMode property using the page directive:

<%@ Page Language="C#" UnobtrusiveValidationMode="None" %>

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com