asp.net ajax (juggling) patterns

18
ASP.NET AJAX (Juggling) Patterns Steve Marx Technical Evangelist Microsoft Corporation

Upload: yered

Post on 22-Feb-2016

38 views

Category:

Documents


0 download

DESCRIPTION

ASP.NET AJAX (Juggling) Patterns. Steve Marx Technical Evangelist Microsoft Corporation. Session Objectives. A Deeper look at AJAX and ASP.NET AJAX Patterns for implementing AJAX scenarios Using partial rendering and Web services together Enhancing page navigation model - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: ASP.NET AJAX  (Juggling)  Patterns

ASP.NET AJAX (Juggling) PatternsSteve Marx

Technical EvangelistMicrosoft Corporation

Page 2: ASP.NET AJAX  (Juggling)  Patterns

Session Objectives

A Deeper look at AJAX and ASP.NET AJAXPatterns for implementing AJAX scenariosUsing partial rendering and Web services togetherEnhancing page navigation modelUnobtrusive inclusion of script functionality

Lots of demos...

Page 3: ASP.NET AJAX  (Juggling)  Patterns

AJAX: Beyond the HypeImproving end-user perception and usability

Faster, smoother, intuitiveVisually appealingPersonalized

Improving network/bandwidth usagePartial renderingLight-weight web service calls

Improving development approach to scriptingNamespaces, interfaces, inheritanceProperties, events, dispose

Page 4: ASP.NET AJAX  (Juggling)  Patterns

DEMO

AJAX =Asynchronous Juggling And XAML

Page 5: ASP.NET AJAX  (Juggling)  Patterns

Partial Rendering• Preserves postback programming model– UpdatePanels declare regions to update– Easy and declarative– Stateful (equivalent to a postback)

Init

Load State

Process PostbackLoad

Postback Events

Save State

PreRender

Render

Unload

PageRequestManager

Form Submit

Form Data + Custom Header

Partial Rendering Response

Click

Page 6: ASP.NET AJAX  (Juggling)  Patterns

DEMO

Optimizing UpdatePanel Usage

Page 7: ASP.NET AJAX  (Juggling)  Patterns

What did we see?• Optimize what to update and when– UpdateMode=“Conditional”– Use triggers, Update() for granular control

• Postbacks are still postbacks–Which user actions should be postbacks?– Carefully evaluate AutoPostBack– Consider alternative means of interactivity

Page 8: ASP.NET AJAX  (Juggling)  Patterns

Logical Navigation• Postbacks flood navigation history with

intermediate steps• AJAX-based pages often have no history– Back button goes the whole way back to the previous

page• How can we improve navigation?– App defines a set of logical views– App controls which updates transition between views– Logical views added to navigation history– Bonus: bookmarking and indexing

Page 9: ASP.NET AJAX  (Juggling)  Patterns

DEMO

Logical Navigation

Page 10: ASP.NET AJAX  (Juggling)  Patterns

Structured Scripting• Increased client UI logic requires structured

approach to scripting– No more ad-hoc global variables, functions– OOP-like scripting system

• Script separate from content– Better designer/developer workflow– Easier to preserve core behavior when script is disabled– “Behaviors” enable unobtrusive script attachment

Page 11: ASP.NET AJAX  (Juggling)  Patterns

DEMO

SelectableBehavior

Page 12: ASP.NET AJAX  (Juggling)  Patterns

Web Services• Data and operations exposed as web services– Support for SOAP (.asmx) and RESTful models– JSON format, object serialization

• Higher-level networking stack– Sys.Net.WebRequest – abstracts XMLHttpRequest– Script proxies for .asmx enable simple method call

model• Ideal for stateless requests– Lean wire format– Generally useful in client-centric apps– Alternative to partial updates where appropriate

Page 13: ASP.NET AJAX  (Juggling)  Patterns

DEMO

Incorporating Web Services

Page 14: ASP.NET AJAX  (Juggling)  Patterns

UpdatePanel or Services?• Complementary models• Partial rendering – when you need state, server-side

control logic– Pros: easy to use, control properties, page state– Cons: full postback, one at a time

• Web services – when your logic is stateless– Pros: light-weight, parallel– Cons: need to write necessary code to package UI as

parameters

Page 15: ASP.NET AJAX  (Juggling)  Patterns

What about search?

• We have data in a database• I want Google/Live/Yahoo to see it…• But there’s JavaScript in between!

• Answer: search sitemaps

Page 16: ASP.NET AJAX  (Juggling)  Patterns

DEMO

Let’s be searchable!

Page 17: ASP.NET AJAX  (Juggling)  Patterns

Summary• AJAX enables rich, next-generation apps• ASP.NET AJAX makes it easy– Integrate AJAX patterns into ASP.NET model– Simple out-of-the-box functionality– Solid platform with extensibility to go further

Page 18: ASP.NET AJAX  (Juggling)  Patterns

Resources• AJAX homepage: http://ajax.asp.net

• Blogs– http://smarx.com – me– http://nikhilk.net – Nikhil Kothari– http://weblogs.asp.net/scottgu – Scott Guthrie– http://weblogs.asp.net/bleroy – Bertrand LeRoy– http://blogs.msdn.com/brada – Brad Abrams– http://www.shankun.com – Shanku Niyogi