Use local version of WebUIValidation.js in ASP.NET

3.4k Views Asked by At

In ASP.NET some scripts are fetched by default from ScriptResource.axd and WebResource.axd (These scrips are: MicrosoftAjaxTimer.js, MicrosoftAjax.js, MicrosoftAjaxWebForms.js in System.Web.Extensions, and DetailsView.js, Focus.js, GridView.js, Menu.js, SmartNav.js, TreeView.js, WebForms.js, WebParts.js and WebUIValidation.js) For instance a script file called ScriptResource.axd?=someGuid.js will be loaded whenever a page with a validator is present.

How do I use my local WebUIValidation.js file instead? (in ASP.NET 4.5)

What I've tried:

I've read Scott Hanselman's old post on this. His idea is using a scriptmanager to override each script with a scriptreference to a local version like this

 <asp:scriptreference name="WebForms.js" assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">

http://www.hanselman.com/blog/ASPNETAjaxScriptCombiningAndMovingScriptResourceaxdsToStaticScripts.aspx

I've tried that, but it doesn't seem to work for WebUIValidation.js. As soon as a page with a validator is loaded, a ScriptResource.axd js file containing the validation script will always be fetched. Hanselman did write a warning (this prior to the release of .NET 4) "NOTE: There're a few controls that don't use the ScriptManager, so they can't have their JavaScript suppressed. So far the Validators are the main culprits. I'm talking to the team and we'll see if we can't get that fixed in 4.0"

But I'm not sure what to do with that information, and I can't find any more recent updates on the subject.

I've also tried replacing the script by using one from my own CDN. I enabled cdn on my Scriptmanager and in the Application_Start of global.asax I've tried setting a custom cdn path ScriptManager.ScriptResourceMapping.AddDefinition("WebUIValidation", new

ScriptResourceDefinition
                    {
                        Path="~/Scripts/WebForms/WebUIValidation.js",
                        CdnPath = "https://dl.dropboxusercontent.com/u/4486136/WebUIValidation.js",
                        LoadSuccessExpression = "window.Sys",
                        CdnSupportsSecureConnection = true
                    });

This just results in 2 script instances being loaded, both from the dropbox AND the default cdn (ajax.aspnetcdn.com). The default cdn is loaded last though so it will be the only one executed. So apparently, it doesnt recognize that I'm trying to overwrite.

I've also tried removing ScriptResource.axd completely, by adding the following to the in my Web.Config

<httpHandlers>
      <remove verb="GET,HEAD" path="ScriptResource.axd" />
    </httpHandlers>

That doesn't seem to do anything.

0

There are 0 best solutions below