.NET Discussion

.NET Issues, Problems, Code Samples, and Fixes

ASP.NET and AJAX: So Freaking Easy (Part 3: Custom Scripts)


As you might have read from my first two posts (Setting Up | Triggers) in this series, Microsoft has done a great job with their AJAX toolkit, making the creation of AJAX-enabled sites easy for those who aren’t familiar with Javascript. This post is going to detail how freaking easy it is to add custom scripts to your application.

Recall (in my first post, see link above) how I mentioned you had to add a ScriptManager to your form in order for ASP.NET AJAX to function. Well, if you’re not adding your own scripts to the site, that’s all you need to do with it. However, if you would like to add your own scripts, doing so is ridiculously easy.

To add custom scripting, within your <asp:scriptmanager></asp:scriptmanager> tags, simply add the following:

<scripts>
<asp:scriptreference path=”~/scriptFolder/yourScript.js” />
</scripts>

You guessed it. That’s it.

Ok, not entirely it, but mostly.  If you want, you can also add these two lines to your scripts to notify the client side ASP.NET AJAX framework when the script is finished loading:

if (typeof(Sys) !== ‘undefined’)
Sys.Application.notifyScriptLoaded();

I’ve tried it without these lines and had no problem running my scripts, but if you are having problems, maybe adding these lines may help.

Advertisements

July 18, 2007 - Posted by | AJAX, ASP.NET, Tips & Tricks

1 Comment »

  1. Great Work!
    Really excited about asp.net ajax and your next article!
    I’m currently building my own blog, and these stuff is gonna use very useful really soon!

    Comment by yonk | July 20, 2007 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: