Baca dalam bahasa Inggris

Bagikan melalui


Getting Client side validation to work while fixing errors of Unobtrusive Validation in ASP.NET 4.5

Moving to ASP.NET 4.5 the existing validation code stops working with a runtime error of Webform UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery.  You can force the old style validation to continue to work with the setting below in the web.config.

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

However, what you really want to do enable the new validation scheme.  I had a lot of trouble getting the client side JavaScript to do the local validation to work.  It still caused the server validation to work, but it didn't the client validation first.  I read a bunch of articles and they all seemed to enable the server validation, but the client validation.  Then until I followed the details in this article:

https://www.c-sharpcorner.com/UploadFile/cd7c2e/ways-to-fix-the-errors-of-unobtrusive-validation/

The basic gist of it is to install several NuGet packages with the client side libraries and changing script manager to actually use those libraries.