O'Reilly logo

Programming Atlas by Christian Wenz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The ScriptManager Control

After this first working example, here is some more background information about how this example worked, and how the other Atlas examples throughout the book work.

The central element of an Atlas-powered ASP.NET page is the ScriptManager, <atlas:ScriptManager>. This control takes care of loading the required JavaScript libraries of Atlas, depending on which browser is used.

If you look at the resulting source code in the browser, you will see that Atlas changed very little—only the <atlas:ScriptManager> element has been replaced with this code (the undecipherable data in the URL will be a bit different on your system):

<script
src="/Atlas/WebResource.axd?d=EiZ5MhryFS7wRPgWKwT3L2TYwCkaaO5mtAO5KyVbAcNmREm0baC0S
_edhhqj_Y6ZuRY56z97Nu5lD2Fw5ITB3mHpybsGTsINHdsdQ_BVGi7cUBG1EWW_cWGx-I8vZeWK0
&amp;t=632781806040000000" type="text/javascript"></script>
<script
src="/Atlas/WebResource.axd?d=EiZ5MhryFS7wRPgWKwT3L2TYwCkaaO5mtAO5KyVbAcNmREm0baC0S
_edhhqj_Y6ZuRY56z97Nu5lD2Fw5ITB3g4TEhGZLS-_Daibixpp8tw1&amp;t=632781806040000000"
type="text/javascript"></script>
<script src="atlasglob.axd" type="text/javascript"></script>

The first <script> tag is used only in non-IE browsers to add a compatibility layer; the second one loads the Atlas core library. The third <script> element contains some client-specific culture information.

Tip

When building the web application in debug mode, the JavaScript code created by WebResource.axd is nicely formatted and some errors are caught. This is convenient for developing purposes, however not required when the web site is deployed.

This ScriptManager element must be present on all pages that use Atlas features. It can also be used to load additional JavaScript libraries, either those that come with Atlas, or your own scripts:

<atlas:ScriptManager ID="ScriptManager1" runat="server">
  <Scripts>
    <atlas:ScriptReference Path="MyScript.js" />
  </Scripts>
</atlas:ScriptManager>

If you are using ASP.NET 2.0 master pages and most of your pages use the Atlas framework, you may consider putting the ScriptManager control on your master page instead of on the individual pages. However when referencing other JavaScript files or web services (as in the “Hello User” example earlier), you run into problems: only one ScriptManager control is allowed per page, so you would have to reference the JavaScript file or web service on all pages, even on those that do not need these external resources.

For this scenario, Atlas provides the ScriptManagerProxy control. This control provides ScriptManager functionality when there is already another ScriptManager present:

<atlas:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
  <Scripts>
    <atlas:ScriptReference Path="MyScript.js" />
  </Scripts>
</atlas:ScriptManagerProxy>

This was just the first step; there’s more to come in the following chapters!

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required