51

Stephen Walther Microsoft [email protected]/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:
Page 3: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

ASP.NET AJAX

Accordion

AlwaysVisibleControl

Animation

AutoComplete

Calendar

CascadingDropDown

CollapsiblePanel

ConfirmButton

Page 4: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

ASP.NET AJAX

AjaxControlToolkit-ScriptFilesOnly.zip

Page 5: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

ASP.NET AJAX

http://www.ASP.net/ajax

Page 6: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Introduction

Web Application Experience in 1993

Page 7: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Introduction

Brendan Eich’s Home Page (the inventor of JavaScript)

Page 8: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Introduction

Super Fancy Ajax Application

Page 9: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

ASP.NET Server-SidePages are rendered on the server and updated through postbacks

ASP.NET Server-Side AJAX (AJAH)Pages are rendered on the server and updated through AJAX requests for HTML

ASP.NET Client-Side AJAXPages are rendered on the client and updated through Ajax requests for JSON

Different Types of Web Applications

Page 10: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Client-Side Application Model

renders once

Ajax Calls (services)

Page 11: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Less roundtrips

Less bandwidth

Less work on the web server

More responsive

Why AJAX Applications Are Good

Page 12: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Two developers: an ASP.NET and JavaScript developer. Ask each developer when a button click event happens…

Why AJAX Applications are Good

Page 13: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Overview: 3 Ways to Build an Application

1. Server-Side ASP.NET

2. Server-Side ASP.NET AJAX

3. Client-Side ASP.NET AJAX

Page 14: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Overview: Features of Client-Side ASP.NET AJAX

1. Declarative Client-Side Controls

2. Command Bubbling

3. Live Bindings

4. Saving and Updating Data

5. Using Templates with JSONP

Page 15: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Server-Side ASP.NET with No Ajax

• Controls• Code• Work

Web Server Web Browser

renders

postback

Page 16: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Creating a Master/Detail Page with Server-Side ASP.NET

Page 17: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Benefits

Safe: No Browser Compatibility Issues

Powerful: Use any programming language

Drawbacks

Responsiveness: User must wait for a postback

Performance: All page content must be rendered for each interaction

Server-Side ASP.NET

Page 18: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Server-Side ASP.NET AJAXwith UpdatePanel

• Controls• Code• Work

Web Server Web Browser

renders

sneakypostback

Page 19: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Creating a Master/Detail Page with Server-Side ASP.NET AJAX

Page 20: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Server-Side ASP.NET AJAX

BenefitsSafe: No Browser Compatibility Issues

Powerful: Use any programming language

Compatible: Retrofit existing ASP.NET applications

DrawbacksResponsiveness: User must wait for a postback (no simultaneous Ajax)

Performance: (most) page content must be rendered for each interaction

Page 21: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Client-Side ASP.NET AJAX Controls

Web Server Web Browser

renders

sneakypostback

• Code• Work • Controls

Page 22: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Creating a Master/Detail Page with Client-Side AJAX Controls

Page 23: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Client-Side ASP.NET AJAX Controls

Perfection Reached!Benefits

Responsive: Events happen when they happen

Performance: Only necessary content is passed between client and server

Clean separation of content and behavior

Page 24: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Data Sources

ASP.NET AJAX is compatible with anything that exposes JSON:

ASMX Web Services

WCF Web Services

HTTP Handlers

JavaScript arrays

ASP.NET MVC JSonResult

ADO.NET Data Services

REST Services

.NET RIA Services

Page 25: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Why Templates are Good

for (var i=0;i < data.length;i++)

{

row = "<tr>";

row += "<td>" + data[i].Title + "</td>";

row += "<td>" + data[i].Director + "</td>";

table += row;

}

$get("movieBody").innerHTML = table;

(Evil)

Page 26: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Why Templates are Good

movieView.set_data(data);

<tbody id="movieBody" class="sys-template">

<tr>

<td>{{ Title }}</td>

<td>{{ Director }}</td>

<td>{{ DateReleased.localeFormat("D") }}</td>

</tr>

</tbody>

(Good)

Page 27: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Rude Objections(impediments to a perfect future)

Browser Back/Forward button

Accessibility

Search Engine Optimization (SEO)

JavaScript disabled (Mobile Devices)

Page 28: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Creating a Master/Detail Page that supports JavaScript failover

Page 29: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Technology Independent

Client-Side ASP.NET AJAX…

Works with any modern browser including IE, Firefox, Chrome, Safari, and Opera.

Works with any back-end technology that exposes JSON (not dependent on ASP.NET)

Works with HTML pages, no need for ASP.NET.

Page 30: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Creating a Master/Detail Page with Pure HTML

Page 31: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Additional ASP.NET AJAX 4.0 Features

Declarative Client-Side Controls

Command Bubbling

Live Bindings

Saving and Updating Data

Page 32: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Declarative Controls

XML Namespacesxmlns:sys=“javascript:Sys”

xmlns:dataview=“javascript:Sys.UI.DataView”

sys:activateActivates declarative controls

sys:attachAttaches a control to a DOM element

Page 33: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Creating a Master/Detail Page with Declarative Client-Side Controls

Page 34: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Command Bubbling

sys:commandA command name such as select, edit, and so on

sys:commandargumentA command argument such as 78

Sys:commandtargetA control or name of a control that is the target of the command.

onCommandDataView event handler that you can use to handle a custom command

Page 35: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Select Command

DataView PropertiesselectedIndex

initialSelectedIndex

selectedData

selectedItemClass

Page 36: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Creating a Master/Detail Page with Command Bubbling

Page 37: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Live Bindings

{{ Title }} Used to execute JavaScript in the context of the current data item

{binding Title }WPF style binding syntax

Supports live binding

Page 38: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Live Bindings

One-way, One-time - The data value is updated only the first time that data binding is invoked.

{{ CompanyName }}

One-way, Live - If the underlying data item is modified, the rendered data value is updated automatically.

<span>{binding CompanyName}</span>

Two-way, Live - If the user changes the data value, the value of the underlying data item is updated. In addition, if the data item is modified from another source, the rendered data value is updated.

<input type=“text” value=“{binding CompanyName}” />

Page 39: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Creating a Master/Detail Page with Live Bindings

Page 40: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Data Sources

ASP.NET AJAX is compatible with anything that exposes JSON:

ASMX Web Services

WCF Web Services

HTTP Handlers

JavaScript arrays

ASP.NET MVC JSonResult

ADO.NET Data Services

REST Services

.NET RIA Services

Page 41: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

DataContext Class

Provides read/write access to data

Supports change tracking in the browser

Send multiple changes in a single batch to the server

Use AdoNetDataContext class with ADO.NET Data Services

Page 42: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Creating a Master/Detail Page that saves data

Page 43: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Using ADO.NET Data Services

Page 45: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Conclusion

Embrace the client-side!For better performance and a better user experience, start writing client-side ASP.NET AJAX applications.

Page 46: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

My Blog

StephenWalther.com

CodePlex ASP.NET Previews

aspnet.CodePlex.com

Official ASP.NET Website

www.ASP.net/ajax

Resources

Page 47: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:
Page 49: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Related Content

Breakout Sessions (session codes and titles)

Interactive Theater Sessions (session codes and titles)

Hands-on Labs (session codes and titles)

Hands-on Labs (session codes and titles)

Page 50: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

Track Resources

Resource 1

Resource 2

Resource 3

Resource 4

Page 51: Stephen Walther Microsoft Stephen.Walther@Microsoftdownload.microsoft.com/download/F/4/3/F43A79B1-707A-4670-863… · More responsive Why AJAX Applications Are Good. Two developers:

© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS,

IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.