Monday, September 8, 2008

Xml-script tutorial

Published: 01 Dec 2006
By: Alessandro Gallo

ASP.NET AJAX provides a way to instantiate client side types using a declarative programming model ala ASP.NET.

Overview
ASP.NET AJAX provides a way to instantiate client side types using a declarative programming model ala ASP.NET. One of the simplest examples of declarative code is the following, which displays a message after the page is loaded:

Note that in order to use the xml-script feature you must download the Futures CTP package from the Microsoft Ajax website and add a reference to the PreviewScript.js file contained in the Microsoft.Web.Preview assembly.

A block of declarative code is always embedded into a script tag with the type attribute set to text/xml-script. The declarative code in the example isn't difficult to understand; we have a root page element that encapsulates a components element, which is the standard form of a generic xml-script block.

Inside the components element we find an application node with the load attribute set to the name of the function declared in the JavaScript code block. The load attribute is parsed as an event name and its value is parsed as the reference to a function that will be added to the corresponding list of event handlers. Since the application element is mapped to the Sys.Application instance, the result is that page_load() will be called when Sys.Application raises its load event.

How is this possible? The answer is that the declarative code is based on a mapping between xml elements and the methods, properties and events exposed by an ASP.NET AJAX class. This kind of mapping exists for every class that exposes a type descriptor, and every class that exposes a type descriptor can be used in declarative code.

Type descriptors
A type descriptor is an object that describes the properties, methods and events exposed by a class. Every class that intends to provide a descriptor should implement the ITypeDescriptorProvider interface, which defines a single method called getDescriptor(); this method must return the type descriptor associated to the class. The prototype of the ITypeDescriptorProvider interface is declared as follows:

More...
http://dotnetslackers.com/articles/atlas/xml_script_tutorial_part1.aspx

ASP.Net Feeds