Your SlideShare is downloading. ×
The Microsoft AJAX Library
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

The Microsoft AJAX Library


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide
  • Beta 2 also defines a global named registerNamespace that can be used in lieu of Type.registerNamespace. However, it's not a "$" function, so it's not included here.
  • You can use initializeRequest to cancel an async callback before it executes. beginRequest and endRequest may be used to display (and hide) callback UIs--for example, custom ProgressUpdate implementations.
  • Show ShoppingCart.aspx and ShoppingCart.asmx.
  • Transcript

    • 1. The Microsoft AJAX Library Jeff Prosise Cofounder, Wintellect [email_address]
    • 2. Architecture Microsoft AJAX Library Browsers (IE, Firefox, Safari, others) Browser Compatibility Asynchronous Communications Script Core Library Base Class Library XHTML/CSS Server Scripts JSON Serializer Web Service Proxies XML-HTTP Stack
    • 3. JavaScript Framework
      • Microsoft AJAX Library is a JavaScript framework
        • Global functions ($ functions)
        • JavaScript base type extensions
        • JavaScript type system
        • Core classes, interfaces, and other types (script core)
        • More classes, interfaces, and other types (BCL)
      • JavaScript framework adds value to JavaScript
        • Adds OOP to JavaScript
        • Makes JavaScript an easier and more productive environment in which to work
    • 4. Global Functions
      • Helper functions for use anywhere, anytime
      • Used in JavaScript emitted by server controls
      Function Description $create Creates and initializes a component $find Retrieves the component with the specified ID $get Retrieves the DOM element with the specified ID $addHandler(s) Registers handlers for DOM event(s) $removeHandler Unregisters a handler for a DOM event $clearHandlers Unregisters handlers for DOM events
    • 5. $get and $create You write this: <asp:DragOverlayExtender ID=&quot;DragOverlayExtender1&quot; TargetControlID=&quot;Target&quot; Enabled=&quot;true&quot; Runat=&quot;server&quot; /> DragOverlayExtender emits this: $create(Sys.Preview.UI.FloatingBehavior, {&quot;handle&quot;:$get('Target')}, null, null, $get('Target'));
    • 6. JavaScript Base Type Extensions
      • Microsoft AJAX Library extends the following JavaScript types by adding new functions
        • Array - add, addRange, contains, insert, remove, etc.
        • Boolean - parse
        • Date - format, parselocale, parseInvariant, parse
        • Error - argumentOutOfRange, invalidOperation, etc.
        • Number - format, parseLocale, parseInvariant
        • Object - getType, getTypeName
        • String - format, endsWith, startWith, trim, etc.
      • See
    • 7. String.Format var s = String.format ('{0}, {1}, and {2}', 1, 2, 3); window.alert (s);
    • 8. Adding OOP to JavaScript
      • JavaScript is object-based but not object-oriented
      • Microsoft AJAX Library adds OOP to JavaScript
        • Namespaces
        • Classes
        • Inheritance
        • Interfaces
        • Enumerated types
      • prototype property forms basis for &quot;classes&quot;
      • Type class provides typing and type reflection
    • 9. JavaScript &quot;Classes&quot; Person = function(name) { this._name = name; } Person.prototype = { get_name: function() { return this._name; } // Declare other class methods here }
    • 10. Using the Person Class var p = new Person('Jeff'); // Displays &quot;Jeff&quot; window.alert(p.get_name());
    • 11. Type Class
      • Adds typing and type reflection to JavaScript
      • Adds key instance methods to all types
        • registerClass, registerInterface
        • initializeBase, getBaseType
        • getBaseMethod, callBaseMethod, and others
      • Implements key &quot;static&quot; type-related methods
        • registerNamespace
        • isNamespace, isClass, isInterface, and others
      • Implemented in MicrosoftAjax.js
    • 12. Registering Namespaces and Classes Type.registerNamespace('Wintellect'); Wintellect.Person = function(name) { this._name = name; } Wintellect.Person.prototype = { get_name: function() { return this._name; } } Wintellect.Person.registerClass('Wintellect.Person');
    • 13. Using Wintellect.Person var p = new Wintellect.Person('Jeff'); // Displays &quot;Jeff&quot; window.alert(p.get_name()); // Displays &quot;Wintellect.Person&quot; window.alert(Object.getTypeName(p));
    • 14. Deriving from Wintellect.Person Wintellect.Programmer = function(name, language) { Wintellect.Programmer.initializeBase(this, [name]); this._language = language; } Wintellect.Programmer.prototype = { get_name: function() { var name = Wintellect.Programmer.callBaseMethod (this, 'get_name'); return name + ' (Programmer)'; }, get_language: function() { return this._language; } } Wintellect.Programmer.registerClass ('Wintellect.Programmer', Wintellect.Person);
    • 15. Using Wintellect.Programmer var p = new Wintellect.Programmer('Jeff', 'C#'); // Displays &quot;Jeff (Programmer)&quot; window.alert(p.get_name()); // Displays &quot;C#&quot; window.alert(p.get_language()); // Displays &quot;Wintellect.Programmer&quot; window.alert(Object.getTypeName(p));
    • 16. MicrosoftAjax.js String- Builder Sys WebRequest- Executor Sys.Net _ProfileService Sys.Services JavaScript- Serializer Sys.Serialization DOMElement Sys.UI _Debug EventArgs Component _Application XMLHttp- EXecutor _WebRequest- Manager WebRequest WebService- Proxy WebService- Error Other ProfileGroup _Authentication- Service DOMEvent Behavior Control Point Bounds _Timer CultureInfo Other
    • 17. StringBuilder var sb = new Sys.StringBuilder(); for (var i = 1; i <= 100; i++) { sb.append(i); // Count from 1 to 100 sb.append('<br/>'); } var text = sb.toString(); // Get the results
    • 18. _Debug Class
      • Debugging class included in script core
        • &quot;assert&quot; method asserts that a condition is true
        • &quot;fail&quot; method breaks into the debugger
        • &quot;trace&quot; method writes trace output
        • &quot;traceDump&quot; dumps an object to trace output
      • Global instance available through Sys.Debug
      // In MicrosoftAjax.js Sys.Debug = new Sys._Debug();
    • 19. Using Sys.Debug // Assert var happy = false; Sys.Debug.assert(happy == true, 'happy is NOT true', false); // Break into the debugger'Somebody is NOT happy');
    • 20. PreviewWebForms.js
      • Partial-page rendering support
        • Sys.WebForms namespace
      • PageRequestManager class
        • Client-side counterpart to UpdatePanel
        • Manages async callbacks used for partial-page rendering and performs content updates using results
        • Client-side OM enables advanced UpdatePanel customizations not possible from server side
      • _UpdateProgress class
    • 21. PageRequestManager Methods
      • Provide programmatic control over client-side PageRequestManager
      Method Description get_isInAsyncPostBack Indicates whether async callback is in progress getInstance Returns reference to current PageRequestManager instance abortPostBack Cancel the async callback that is currently in progress add_* Registers handlers for PageRequestManager events remove_* Deregisters handlers for PageRequestManager events
    • 22. PageRequestManager Events
      • PageRequestManager fires client-side events
      • Hook events on client for advanced customizations
      Event Description initializeRequest Fired before async callback commences beginRequest Fired when async callback commences pageLoading Fired following an async callback (before content is updated) pageLoaded Fired following a postback or callback (after content is updated) endRequest Fired when async callback completes
    • 23. Canceling Updates <asp:Button ID=&quot;CancelButton&quot; Runat=&quot;server&quot; Text=&quot;Cancel&quot; OnClientClick=&quot;cancelUpdate(); return false&quot; /> . . . <script type=&quot;text/javascript&quot;> function cancelUpdate() { var obj = Sys.WebForms.PageRequestManager.getInstance(); if (obj.get_isInAsyncPostBack()) obj.abortPostBack(); } </script>
    • 24. PageRequestManager
    • 25. PreviewScript.js BindingBase Sys.Preview Sys.Preview.UI DataControl Sys.Preview.Data DataColumn Sys.Preview.UI.Data ServiceMethod- Request Other Namespaces Binding Action InvokeMethod- Action SetProperty- Action Color Validator Label Button CheckBox DataNavigator ItemView Profile Timer Counter Other TextBox Selector Other ListView XSLTView Other DataRow DataTable DataView DataFilter DataSource Other Other
    • 26. Sys.Preview.UI
      • Classes that abstract HTML control elements
        • Button, Label, TextBox, Selector, etc.
      • Base functionality defined in Sys.UI.Control
        • get_visible, set_visible
        • get_parent, set_parent
        • And so on
      • Control classes simplify JavaScript and facilitate browser independence
    • 27. Using Control Classes <input type=&quot;text&quot; id=&quot;Input&quot; />&nbsp; <input type=&quot;button&quot; id=&quot;MyButton&quot; value=&quot;Click Me&quot; />&nbsp; <span id=&quot;Output&quot; /> ... <script type=&quot;text/javascript&quot;> var g_textBox; var g_label; function pageLoad() { g_textBox = new Sys.Preview.UI.TextBox($get('Input')); var button = new Sys.Preview.UI.Button($get('MyButton')); g_label = new Sys.Preview.UI.Label($get('Output')); button.initialize(); button.add_click(onClick); } function onClick() { g_label.set_text(g_textBox.get_text()); } </script>
    • 28. XML Script
      • Alternative to imperative JavaScript
        • The &quot;other way&quot; to program the Microsoft AJAX Library
      • Supporting infrastructure found in PreviewScript.js
        • XML parser translates declarations into actions
      <script type=&quot;text/xml-script&quot;> <page xmlns:script=&quot;;> <!-- XML script goes here --> </page> </script>
    • 29. Using Control Classes (XML Script) <input type=&quot;text&quot; id=&quot;Input&quot; />&nbsp; <input type=&quot;button&quot; id=&quot;MyButton&quot; value=&quot;Click Me&quot; />&nbsp; <span id=&quot;Output&quot; /> <script type=&quot;text/xml-script&quot;> <page xmlns:script=&quot;;> <components> <textBox id=&quot;Input&quot; /> <button id=&quot;MyButton&quot;> <click> <invokeMethodAction target=&quot;TextBinding&quot; method=&quot;evaluateIn&quot; /> </click> </button> <label id=&quot;Output&quot;> <bindings> <binding id=&quot;TextBinding&quot; dataContext=&quot;Input&quot; dataPath=&quot;text&quot; property=&quot;text&quot; automatic=&quot;false&quot; /> </bindings> </label> </components> </page> </script>
    • 30. Sys.Preview.[UI.].Data
      • Contains classes that support rich client-side data binding
      • ItemView and ListView do client-side rendering
      • DataSource links data consumers to data service and supports 2-way data binding
      DataControl Sys.Preview.Data DataColumn Sys.Preview.UI.Data DataNavigator ItemView ListView XSLTView Other DataRow DataTable DataView DataFilter DataSource Other
    • 31. ListView and DataSource <div id=&quot;Books&quot;></div> <div style=&quot;display: none;&quot;> <div id=&quot;LayoutTemplate&quot;> <ul id=&quot;ItemTemplateParent&quot;> <li id=&quot;ItemTemplate&quot;><span id=&quot;BookTitle&quot;></span></li> </ul> </div> </div> <script type=&quot;text/xml-script&quot;> <page xmlns:script=&quot;;> <components> <dataSource id=&quot;BooksDataSource&quot; serviceURL=&quot;Books.asmx&quot; autoLoad=&quot;true&quot; /> <listView id=&quot;Books&quot; itemTemplateParentElementId=&quot;ItemTemplateParent&quot;> <bindings> <binding dataContext=&quot;BooksDataSource&quot; dataPath=&quot;data&quot; property=&quot;data&quot; /> </bindings> <layoutTemplate> <template layoutElement=&quot;LayoutTemplate&quot; /> </layoutTemplate> <itemTemplate> ... </itemTemplate> </listView> </components> </page> </script>
    • 32. Data Service [ScriptService] public class Books : DataService { [WebMethod] [DataObjectMethod(DataObjectMethodType.Select)] public Book[] GetTitles() { // TODO: Generate and return Book array } } public class Book { private string _title; [DataObjectField(true)] public string Title { get { return _title; } set { _title = value; } } }
    • 33. Enabling Data Binding
      • Register JSON converters in Web.config
      <system.web.extensions> <scripting> <webServices> <jsonSerialization> <converters> <add name=&quot;DataSetConverter&quot; type=&quot;Microsoft.Web.Preview.Script.Serialization.Converters.DataSetConverter, ...&quot; /> <add name=&quot;DataRowConverter&quot; type=&quot;Microsoft.Web.Preview.Script.Serialization.Converters.DataRowConverter, ...&quot; /> <add name=&quot;DataTableConverter&quot; type=&quot;Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter, ...&quot; /> </converters> </jsonSerialization> </webServices> </scripting> </system.web.extensions>
    • 34. Client-Side Data Binding
    • 35. PreviewDragDrop.js
      • Adds drag-drop support to BCL
        • Sys.Preview.UI namespace
      • _DragDropManager provides core support
        • Global instance named DragDropManager
      • IDropSource and IDropTarget interfaces define signatures for drop-source and drop-target classes
      • DragDropList and DraggableListItem provide canned implementation of reorderable lists
      • FloatingBehavior provides generic mechanism for floating images, DIVs, and other entities
    • 36. Floating an Image <img id=&quot;FloatMe&quot; src=&quot;...&quot;> ... <script type=&quot;text/javascript&quot;> function pageLoad() { var float = new Sys.Preview.UI.FloatingBehavior ($get('FloatMe')); float.set_handle($get('FloatMe')); float.initialize(); } </script>
    • 37. Floating an Image (XML Script) <img id=&quot;FloatMe&quot; src=&quot;...&quot;> ... <script type=&quot;text/xml-script&quot;> <page xmlns:script=&quot;http://.../xml-script/2005&quot;> <components> <image id=&quot;FloatMe&quot;> <behaviors> <floatingBehavior handle=&quot;FloatMe&quot; /> </behaviors> </image> </components> </page> </script>
    • 38. Drag-and-Drop
    • 39. PreviewGlitz.js
      • Adds UI enhancements to BCL
        • Sys.Preview.UI.Effects namespace
      • OpacityBehavior class wraps opacity of elements
      • LayoutBehavior class wraps layout (size and pos)
      • Animation and derivatives support animations
      Property- Animation Interpolated- Animation Discrete- Animation Number- Animation Length- Animation Composite- Animation Fade- Animation
    • 40. Fading In an Image <img id=&quot;SplashImage&quot; src=&quot;...&quot;> ... <script type=&quot;text/javascript&quot;> function pageLoad() { var image = new Sys.Preview.UI.Image ($get('SplashImage')); var fade = new Sys.Preview.UI.Effects.FadeAnimation(); fade.set_target(image); fade.set_effect (Sys.Preview.UI.Effects.FadeEffect.FadeIn); fade.set_duration(3); fade.set_fps(20);; } </script>
    • 41. Fading In an Image (XML Script) <img id=&quot;SplashImage&quot; src=&quot;...&quot;> ... <script type=&quot;text/xml-script&quot;> <page xmlns:script=&quot;http://.../xml-script/2005&quot;> <components> <image id=&quot;SplashImage&quot; /> <fadeAnimation id=&quot;fade&quot; target=&quot;SplashImage&quot; effect=&quot;FadeIn&quot; duration=&quot;3&quot; fps=&quot;20&quot; /> <application> <load> <invokeMethodAction target=&quot;fade&quot; method=&quot;play&quot; /> </load> </application> </components> </page> </script>
    • 42. Discussion