Hi
I am getting error when i use Regular Expression
Bank Name *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() +3886983
System.Web.UI.WebControls.BaseValidator.RegisterUnobtrusiveScript() +14
System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +11612054
System.Web.UI.Control.PreRenderRecursiveInternal() +132
System.Web.UI.Control.PreRenderRecursiveInternal() +227
System.Web.UI.Control.PreRenderRecursiveInternal() +227
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3671
Thanks
Naimish MakwanaRank #324 · 7.7K reputationPosted Aug 28, 2024, 2:50 AM EDT
The error you're encountering is due to the fact that your ASP.NET Web Forms application is set to use unobtrusive validation, which requires jQuery. However, jQuery is not currently mapped in your project, leading to the exception.
Here are steps to resolve this issue:
1. Add jQuery Script Mapping
You need to add a
ScriptResourceMappingfor jQuery in yourGlobal.asax.csfile or directly in your ASP.NET page. Here's how you can do it:In
Global.asax.cs:protected void Application_Start(object sender, EventArgs e) { ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition { Path = "~/Scripts/jquery-3.6.0.min.js", // Update the path based on where jQuery is located in your project DebugPath = "~/Scripts/jquery-3.6.0.js", CdnPath = "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.6.0.min.js", CdnDebugPath = "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.6.0.js" }); }2. Include jQuery Script in Your Page
Alternatively, you can directly include the jQuery script in your ASP.NET page. For example, in your
Department.aspxpage:3. Check Web.config
Ensure that unobtrusive validation is enabled in your
Web.config:4. Make Sure jQuery Is Correctly Loaded
Ensure that jQuery is properly loaded by opening your page in a browser, inspecting the page source, and checking the console for any errors related to jQuery.
5. Disable Unobtrusive Validation (Optional)
If you don't need unobtrusive validation, you can disable it by modifying your
Web.config:This change will revert to the old-style validation that doesn't require jQuery.
After making these changes, your regular expression validator should work without throwing the exception.
Aman GuptaRank #193 · 12.4K reputationPosted Aug 28, 2024, 12:35 PM EDT
Hi,
The error you're encountering is related to the requirement for jQuery when using Unobtrusive Validation in ASP.NET WebForms. By default, ASP.NET WebForms uses unobtrusive validation, which depends on jQuery. If jQuery is not available on the page, you'll get the error message:
WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).
Solution
To resolve this issue, you can add a ScriptResourceMapping for jQuery in your Global.asax file, or directly include jQuery in your ASP.NET WebForm.
1. Adding ScriptResourceMapping in Global.asax:
Open your Global.asax file and add the following code in the Application_Start method:
protected void Application_Start(object sender, EventArgs e) { ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition { Path = "~/Scripts/jquery-3.6.0.min.js", // Adjust the path to your jQuery version DebugPath = "~/Scripts/jquery-3.6.0.js", // Adjust the path to your jQuery version CdnPath = "https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js", CdnDebugPath = "https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.js", CdnSupportsSecureConnection = true, LoadSuccessExpression = "window.jQuery" }); }Make sure that the path specified in Path and DebugPath matches the location of your jQuery files in your project.
2. Including jQuery Directly in the WebForm:
Alternatively, you can include jQuery directly in your ASPX page by adding a
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts