Tags

, ,

MicrosoftAjax.js represent the base of ASP.NET Ajax client side development. It is a library developed by Microsoft which is automatically placed in your page if you include asp:ScriptManager control.  The file is taken from server resources and you cannot change it or add new code to it if you do not place it into a custom location.

But how do I specify the custom location for this file? First let’s start with the beginning and see how asp:ScriptManager is handling JavaScript files.

JavaScript files are added within Scripts tag inside asp:ScriptManager by specifying name or path to the file.

<asp:ScriptManager runat="server" LoadScriptsBeforeUI="false" ID="JSManager">
<Scripts>
       <asp:ScriptReference Name="MicrosoftAjax.js" />
       <asp:ScriptReference Name="MicrosoftAjaxWebForms.js" />
       <asp:ScriptReference Path="/Scripts/Framework.js" />
</Scripts>
</asp:ScriptManager>

Code posted above includes “MicrosoftAjax.js” and “MicrosoftAjaxWebForms.js” files from default location (those two files should be used together) and a custom JavaScript file from “Scripts” directory called “Framework.js”.

Now is time to create a copy of ASP.NET Ajax files and move them to “Scripts” directory near my custom code file.  By adding path near name attribute,  asp:ScriptManager will look for the location I specified, despite official documentation (please drop me a note if I am wrong).

<asp:ScriptManager runat="server" LoadScriptsBeforeUI="false" ID="JSManager">
<Scripts>
       <asp:ScriptReference Name="MicrosoftAjax.js" Path="/Scripts/MicrosoftAjax.js" />
       <asp:ScriptReference Name="MicrosoftAjaxWebForms.js" Path="/Scripts/MicrosoftAjaxWebForms.js" />
       <asp:ScriptReference Path="/Scripts/Framework.js" />
</Scripts>
</asp:ScriptManager>

Making this modifications I am now able to change built-in code and adapt it to new non-supported browsers like Chrome.

Advertisements