Oz Cohen Oz Cohen - 1 month ago 12
ASP.NET (C#) Question

WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

The error:


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() +2879797

System.Web.UI.WebControls.BaseValidator.RegisterUnobtrusiveScript()
+11 System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +9705473 System.Web.UI.Control.PreRenderRecursiveInternal() +88
System.Web.UI.Control.PreRenderRecursiveInternal() +160

System.Web.UI.Control.PreRenderRecursiveInternal() +160

System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+883


The markup & code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="change pass.aspx.cs" Inherits="change_pass" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Account Set|HaD</title>
<link href="MyStyle.css" rel="stylesheet" />
<link rel="shortcut icon" type="icon/x-icon" href="Main Images/HaD simbul.jpg" />
</head>
<body style="background-image:url(Main%20Images/settings%20back.jpg);background-size:cover;color:goldenrod;font-size:larger">
<form id="form1" runat="server">
<center><h1>Account Settings</h1></center>
<div style="background-color:#100f0f">
<center>
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell><nav class="menu">
<ul class="clearfix">
<li>
<a href="#" style="text-decoration:none;">Profile Settings</a>

<ul class="sub-menu">
<li><a href="change username.aspx">Change User name</a></li>
<li><a href="change pass.aspx">Change password</a></li>
<li><a href="change email.aspx">Change Email</a></li>
</ul>
</li>
</ul>
</nav></asp:TableCell>
<asp:TableCell><span class="set-manu"><a href="Dealete account.aspx">Delete Acount</a></span></asp:TableCell>
<asp:TableCell><span class="set-manu"><a href="Bank Settings.aspx">Bank Settings</a></span></asp:TableCell>
</asp:TableRow>
</asp:Table>
</center>
</div>
<div id="Connected" runat="server" style="position:relative;margin-left:3%">
<h2 style="color:red">Welcome <b><span id="Usernamec" runat="server" style="color:goldenrod"></span></b></h2><br />
</div>
<div id="change">
<asp:TextBox CssClass="txt" ID="txtpass" runat="server" type="password" placeholder="Enter New Password"></asp:TextBox>
<span style="color:red"><asp:RequiredFieldValidator ID="Rfvpass" runat="server" ErrorMessage="<img src='http://www.clker.com/cliparts/a/T/A/y/b/C/x-mark-hi.png' width='30px' height='30px'/>password is Required" ControlToValidate="txtpass"></asp:RequiredFieldValidator></span><br /><br />
<asp:TextBox CssClass="txt" ID="re" runat="server" type="password" placeholder="Repeat New Password"></asp:TextBox>
<span style="color:red"><asp:RequiredFieldValidator ID="RfvRepass" runat="server" ErrorMessage="<img src='http://www.clker.com/cliparts/a/T/A/y/b/C/x-mark-hi.png' width='30px' height='30px'/>Please Repeat password" ControlToValidate="re"></asp:RequiredFieldValidator>
<br /><asp:CompareValidator ID="Cmpass" runat="server" ErrorMessage="<img src='http://www.clker.com/cliparts/a/T/A/y/b/C/x-mark-hi.png' width='30px' height='30px'/>The passwords dont mach" ControlToCompare="txtpass" ControlToValidate="re"></asp:CompareValidator></span>
</div>
<a class="button" href="index.aspx">Home page</a> <a class="button" href="Account settings.aspx">Account Settings</a>
</form>
</body>
</html>

Answer

Disable UnobtrusiveValidationMode by adding this to web.config:

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

UnobtrusiveValidationMode uses data-attributes and late bound JS instead of inline JS for validation. Setting value to None will use inline JS instead.

From MSDN:

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.