Article Over An exception with required field validator

Sharing is caring!

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

This article will give you the complete guidance about how to remove such kind of errors that is title of article in .Net Framework 4.5. This error comes if you are going to use the RequiredFieldValidator control on any of the server control. Below is complete guidance with examples

Create Web Form
Here is complete code of designing of aspx page.

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Home.aspx.cs” Inherits=”Home” %>

<!DOCTYPE html>

<html xmlns=””>

<head runat=”server”>




<form id=”form1″ runat=”server”>


Employee id <asp:TextBox ID=”employee_id” runat=”server” ValidateRequestMode=”Enabled”></asp:TextBox>

<asp:RequiredFieldValidator ID=”validate_employee_id” runat=”server” ControlToValidate=” employee_id ” ErrorMessage=”Empid Can not be left blank” ForeColor=”#CC0000″></asp:RequiredFieldValidator>

<br />

<br />

Employee Name:&nbsp;<asp:TextBox ID=”employee_name” runat=”server”></asp:TextBox>

<br />

<br />

Designation:&nbsp;<asp:TextBox ID=”employee_designation” runat=”server”></asp:TextBox>

<br />

<br />

Company:&nbsp;<asp:TextBox ID=”employee_company” runat=”server”></asp:TextBox>

&nbsp;<br />

<br /> <asp:Button ID=”save” runat=”server” OnClick=”save_Click” Text=”Click to Submit” Height=”27px” Width=”66px” />


<asp:Button ID=”fetch” runat=”server” Text=”Retrieve” Height=”26px” Width=”62px” OnClick=”fetch_Click” />

<br />

<br />





 Server Side Code

You need to create a click event for your button control that shows input values.

using System;

using System.Collections.Generic;

using System.Configuration;

using System.Data;

using System.Data.SqlClient;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class Home : System.Web.UI.Page


   SqlConnection mycon = new SqlConnection(ConfigurationManager.ConnectionStrings[“conn1”].ConnectionString);

   SqlCommand mycommand;

   SqlDataReader mydr;

   protected void Page_Load(object sender, EventArgs e)



   protected void save_Click(object sender, EventArgs e)




           mycommand = new SqlCommand(“insert into employeedetails values(@id,@name,@designation,@company)”, mycon);

           mycommand.Parameters.Add(“@id”, SqlDbType.NVarChar).Value = employee_id.Text;

           mycommand.Parameters.Add(“@name”, SqlDbType.NVarChar).Value = employee_name.Text;

           mycommand.Parameters.Add(“@designation”, SqlDbType.NVarChar).Value = employee_designation.Text;

           cmyommand.Parameters.Add(“@company”, SqlDbType.NVarChar).Value = employee_company.Text;


            if (Convert.ToBoolean(command.ExecuteNonQuery()))


               Response.Write(“<script>alert(‘Record Successfully Inserted’);</script>”);




               Response.Write(“<script>alert(‘Record could not be Inserted’);</script>”);



       catch (Exception ex)









   protected void fetch_Click(object sender, EventArgs e)




           mycommand = new SqlCommand(“select * from employeedetails where empid=@empid”, mycon);

           command.Parameters.Add(“@empid”, SqlDbType.NVarChar).Value = employee_id.Text;


           mydr = command.ExecuteReader();

           DataTable mydt = new DataTable();


           if (mydt.Rows.Count > 0)


               Employee_name.Text = mydt.Rows[0][“name”].ToString();

               Employee_designation.Text = mydt.Rows[0][“Designation”].ToString();

               Employee_company.Text = mydt.Rows[0][“Company”].ToString();



       catch (Exception ex)










Now Run the Application

Now run your website and leave employee id field blank and click on submit button. You

will get below error message as figure 1.1.

.Net Training (SSDN Technologies)

Figure 1.1 : Error Message After submit button click

Resolve Error

Now we will add a key for Unobtrusive Validation Mode under <appSettings> tag in web.config file as shown in below code.

<?xml version=”1.0″?>


For more information on how to configure your ASP.NET application, please visit




   <add name=”conn1″ connectionString=”Data Source=ANKIT\SQLEXPRESS;Initial Catalog=db1;User Id=sa;Password=1234″/>



   <compilation debug=”true” targetFramework=”4.5″/>

   <httpRuntime targetFramework=”4.5″/>



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



Validation Message

After that again run the same page and leave blank Employee_id field and click on submit button. Now you will get a validation message as shown in figure 1.2

.Net Training (SSDN Technologies 2)

                                                                   Figure 1.2 Validation message

Now insert value in employee id field and run the application again. Now You will get desired result as shown in figure 1.3.

.Net Training (SSDN Technologies 23

You May Also Like

About the Author: SSDN Technologies

0 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
0 Comment authors
Recent comment authors
newest oldest most voted
Notify of