240 likes | 432 Views
ASP.NET AJAX 4.O Preview. Jurgen Postelmans jurgen@u2u.be U2U http://www.u2u.be/res/Articles.aspx. Objectives and Takeaways. Session Objectives Understand what AJAX is. Show how Microsoft ASP.NET AJAX is being used today Understand the pure AJAX model
E N D
ASP.NET AJAX 4.O Preview Jurgen Postelmans jurgen@u2u.be U2U http://www.u2u.be/res/Articles.aspx
Objectives and Takeaways • Session Objectives • Understand what AJAX is. • Show how Microsoft ASP.NET AJAX is being used today • Understand the pure AJAX model • Introduce the new AJAX features in ASP.NET 4.0 (client data, client templates, declarative markup, bindings, command bubbling, etc.) • Key Takeaways • ASP.NET AJAX development is more active than ever • Client data-driven UI is easier than ever
What Is AJAX All About?Server AJAX versus "pure" AJAX Server AJAX Rendering Rendering Initial request: HTML HTML Form POST HTML + JSON JSON JSON
Microsoft AJAX TodayA server-side focus • UpdatePanel • Server Controls and Extenders • Developers shielded from JavaScript • Client-focused development possible but less familiar
The “Pure AJAX” ModelWhy it matters It's all about the standard browser • No plug-in necessary • Network payload is way smaller(data < HTML, no ViewState round-tripping) • Less round-tripping to the server • More reactive UI
Client DataFrom Web services to plain JavaScript data • Any JSON/POX Web service • .asmx • WCF • HttpHandler • JSONResult • etc. • ADO.NET Data Services • Client AdoNetServiceProxy control • Server data gets represented on the client as plain JavaScript objects • Javascript Arrays and objects.
Demo of Pure AJAX with ASP.NET AJAX 3.5
ASP.NET AJAX 4.0A client application model • Client-side applications get a lot easier • Server provides JSON data, not HTML • Client data sources • Client template rendering • Live Bindings • Declarative instantation
Client TemplatesSimple rendering on the client • On the server: • <ItemTemplate> <li><%# Eval("Name") %></li></ItemTemplate> • On the client: • <ul class=“sys-template”> <li>{{ Name }}</li></ul>
The DataView • DataView control renders data using a template • Repeater if data is an array • Details View if data is an object
Client TemplatesSimple rendering on the client • Design Goals • Performance • Simplicity and readability • Security • XHTML (if you care about that) • Easily embed data into markup: {{ Name }} • Default data context is the current data item • Expression language is JavaScript:{{BirthDate.localeFormat(“dd/MM/yyyy”)}} • Interspersed code and markup • Declarative behavior and events
The Microsoft AJAX LibraryA component model for the browser • Namespaces • Components • Controls and Behaviors • $create(Sys.UI.DataView, {serviceUri: “../AdventureWorksAdo.svc”},{},{}, $get(“productListView”));equivalent to:vardv = new Sys.UI.DataView($get(“productListView”));dv.set_serviceURI(“../AdventureWorksAdo.svc”);dv.initialize();
Declarative ComponentsExtending markup semantics • Instantiate controls and behaviors from markup • XHTML-compliant markup • Registration:xmlns:dataview=“javascript:Sys.UI.DataView” • Instantiation:<div sys:attach=“dataview”></div> • Setting properties:dataview:serviceuri=“AdventureWorksAdo.svc” • No JavaScript
Command BubblingA simpler approach to building interactive UI • Similar to the server-side concept<asp:buttoncommandName=“select” … /><button sys:command=“select” … /> • Associates commands with UI elements • Commands bubble up the DOM • Controls handle commands they understand • No JavaScript
Live BindingsFrom data to UI and back • WPF-like syntax<span>{binding Name}</span><input value=“{binding Name}” … /> • They really are live • Reflect changes live from data • Reflect changes live back to data from user input • Changes get instantly propagated • No round-trip to the server • Convert and ConvertBack functions • No JavaScript
What We’ve LearnedA client data drill-down • Getting data from ADO.NET Data Services • Formatting data into HTML using templates • Declaratively instantiating components • Bubbling commands • Binding UI to data • ASP.NET AJAX development is more active than ever • Client data-driven UI is easier than ever
What Else In ASP.NET AJAX 4.0?…and beyond? • Client data • Sorting, pagination, and filtering • Automatically sending changes to the server • ASPX server integration • More controls in the AJAX Control Toolkit • Search engine optimization • jQuery • Splitting the framework into smaller pieces