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.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ValidationApplication.Default" %>

<!DOCTYPE html>
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head id="Head1" runat="server">
   
<title>Required Field example</title>

</
head>
<
body>
   
<form id="form1" runat="server">

   
<div>

        Name :

        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>

        <asp:RequiredFieldValidator ID="reqName" runat="server" Display="Dynamic" ControlToValidate="txtName"

            Text="Name is empty" Style="color: red"></asp:RequiredFieldValidator>

        <asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClick="btnSubmit_Click" />

   
</div>

   
</form>

</
body>
</
html>

Server Side Code

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

using System;

using System.Web.UI;

namespace ValidationApplication

{
    public partial class Default : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {
 
        }

        protected void btnSubmit_Click(object sender, EventArgs e)

        {

            if (Page.IsValid)

            {

                Response.Write("My name is :" + txtName.Text);

            }

        }

    }

}

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.

<?xml version="1.0"?>

<configuration>
    <system.web>

      <compilation debug="true" targetFramework="4.5" />

      <httpRuntime targetFramework="4.5" />

    </system.web>

  <appSettings>

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

  </appSettings>

</
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

Up Next
    Ebook Download
    View all
    Learn
    View all