Using Custom Script Files with ASP.NET AJAX

I am slowly but surely started to really get the hang of this AJAX stuff, especially with the ASP.NET AJAX framework. I have been having an issue with some basic existing JavaScript working with the framework though. Finally I broke down and read the ASP.NET AJAX documentation, gasp.

Turns out you need to register your custom scripts with the ScriptManager on the page. The ScriptManager has a few properties we can leverage to include our own scripts and web services. You are not limited to JavaScript files you can also leverage JavaScript resrouces embedded in an assembly too.

There are four properties that can be added to the ScriptManager to leverage your own custom code, AuthenticationService, ProfileService, Scripts and Services. Using the Scripts property allows you to register your own JavaScript files.

        <asp:ScriptManager ID="ScriptManager1" runat="server">
                <asp:ScriptReference Path="~/MyLocalScripts.js" />
               <asp:ScriptReference Assembly="MyClasses"  Name ="MyEmbeddedScripts.js" />

Now you can reference the ASP.NET AJAX framework in your own JavaScript routines. I find it very helpful because they have already encapsulated so much for us in the framework.

If you were worried about the SrciprManagerProxy object, they all work with it too. So you should have no problem with Master Pages. Also I believe you should be able to register your scripts at run-time too. When I get a chance I will go over that too.

Share This Article With Your Friends!

Googles Ads Facebook Pixel Bing Pixel LinkedIn Pixel