08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

336<br />

CHAPTER 14 ■ JAVASCRIPT PROGRAMMING WITH <strong>ASP</strong>.<strong>NET</strong> <strong>AJAX</strong><br />

runtime, <strong>and</strong> thus the underpinnings for much of the object-oriented functionality in<br />

your class are available. However, you have to be careful about how you declare your<br />

class to the page. You can do it within a tag that references the saved Boat.js, but<br />

you will end up with some problems if the browser tries to parse your class definition<br />

before it parses the supporting classes. In this case, it will not recognize the Type class in<br />

the very first line, <strong>and</strong> you’ll get an error.<br />

A better approach is to register your class with the ScriptManager, <strong>and</strong> have it manage<br />

downloading your script to the client.<br />

When you place a ScriptManager on your page, you can select it in Visual Studio<br />

<strong>and</strong> inspect its Scripts collection using the Property Editor. This will call up the<br />

ScriptReference Collection Editor. On here, you can click Add to add a new Scripts<br />

reference <strong>and</strong> specify the path of the new reference to the script that you want to<br />

download—in this case, Boat.js (see Figure 14-1).<br />

Figure 14-1. Adding a script reference to the ScriptManager<br />

This will create a declaration on your page that looks like this:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!