Alasse Alasse - 3 months ago 19
ASP.NET (C#) Question

ASP.net RequiredFieldValidator VisualStudio 2012

I am developing a project with ASP.net c#.
I want RequiredFieldValidator to check my textbox. I am adding validator, and it works perfectly fine in Visual Studio 2010. But once i did the same thing, exactly same thing, it does not work in Visual Studio 2012. I am recieving this error:

[InvalidOperationException: WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).]
System.Web.UI.ClientScriptManager.EnsureJqueryRegistered() +2171326
System.Web.UI.WebControls.BaseValidator.RegisterUnobtrusiveScript() +10
System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +9576177
System.Web.UI.Control.PreRenderRecursiveInternal() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974


My regards...

Answer

See here http://connect.microsoft.com/VisualStudio/feedback/details/735928/in-asp-net-web-application-visual-basic-the-requiredfieldvalidator-doest-work.

It looks like you have to either remove this line:

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

Or change it to this:

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

Which will disable it for you.

Alternatively you could add something like this to your Global.asax

ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition {
     Path = "~/scripts/jquery-1.4.1.min.js",
     DebugPath = "~/scripts/jquery-1.4.1.js",
     CdnPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.1.min.js",
     CdnDebugPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.1.js"
});

Hopefully this gets you squared away!