160 likes | 325 Views
Developing ASP.NET AJAX Components. Hristo Deshev t elerik. What we are after. Introduce the ASP.NET AJAX client-side platform; Create script-rich ASP.NET controls; Extend existing controls with behaviors. Warning: lots of code ahead!. Why develop ASP.NET AJAX components?.
E N D
Developing ASP.NET AJAX Components Hristo Deshev telerik
What we are after • Introduce the ASP.NET AJAX client-side platform; • Create script-rich ASP.NET controls; • Extend existing controls with behaviors. • Warning: lots of code ahead!
Why develop ASP.NET AJAX components? • Boost developer productivity: • help inexperienced script authors; • reuse, reuse, reuse. • Standardize client-side code: • achieve consistency across your code base; • get new team members up to speed quickly.
JavaScript OOP language services • Strictly defined types: • Inheritance and “virtual” methods • Interfaces • Properties • Events and delegates
JavaScript “classes” • Inheritance and constructor chaining:MyClass = function(param) { MyClass.initializeBase(this, [param]);} • Virtual methods and method overrides:dispose : function(){ MyClass.callBaseMethod(this,‘dispose'); //…}
DOM abstraction layer • DOM events: • $addHandler():$addHandler(this.nextButton, "click", this._nextButton_onclick$delegate); • $addHandlers(), $removeHandler(), $clearHandlers() • Event object helpers: • target element; • screen coordinates; • cancel default action; • stop event propagation, etc.
JavaScript components • Types that implement IComponent: Sys.UI.Control and Sys.UI.Behavior; • Can expose custom events; • Hosted inside a container: Sys.Application. • Discoverable: $find(“MyComponent1”); • Conform to rules for initialization, disposal, etc.
Component events • DelegatesFunction.createDelegate(listener, listener.ImageChanged) • Expose and raise events:add_imageChanged : function(handler) { this.get_events().addHandler("imageChanged", handler);}raiseImageChanged : function() {var eh = this.get_events().getHandler("imageChanged");if (eh) {eh(this, Sys.EventArgs.Empty);}} • Subscribe to an event:slideShow.add_imageChanged(imageChangedDelegate);
Demo Client-side components: the ImageSlideShow client control
Script Controls • Server-side controls associated with script code on the client. • Implement IScriptControl and register with the ScriptManager. • Provide a number of ScriptDescriptor objects to describe what should happen on the client.
Demo Building server-side script controls: the ImageSlideShow server control
Behaviors • Have nothing to do with IE behaviors; • Inherit from Sys.UI.Behavior; • Enhance existing controls by providing additional… behavior.
Extender controls • Server-side controls that extend another server-side control. • Implement IExtenderControl and register with the ScriptManager. • Register a client-side behavior component by providing one or more ScriptBehaviorDescriptor objects.
Demo Building behaviors and extender controls: HoverZoomBehavior and HoverZoomExtender
Additional Resources • The official ASP.NET AJAX site: http://ajax.asp.net/ • The ASP.NET AJAX Control Toolkit: http://ajax.asp.net/ajaxtoolkit/ • The ASP.NET AJAX forums hosted on http://forums.asp.net/ • My blog:http://blogs.telerik.com/blogs/twisted_asp_net/