Welcome to Professional ASP.NET - Chris Love's Official Blog Sign in | Join | Help

Chris Love's Official ASP.NET Blog

Chris Love's Helpful tips, tricks and pragmatic development knowledge for the ASP.NET world.
Add to Technorati Favorites


ASP Insider
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">
            <Scripts>
                <asp:ScriptReference Path="~/MyLocalScripts.js" />
               <asp:ScriptReference Assembly="MyClasses"  Name ="MyEmbeddedScripts.js" />
            </Scripts>           
        </asp:ScriptManager>

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.

Posted: Friday, November 30, 2007 11:01 PM

by Chris Love
Filed under: ,

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS