asp.net 4 and ajax

23
Visual Studio 2010 and .NET Framework 4 Training Workshop

Upload: kulveersingh

Post on 10-May-2015

2.497 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: ASP.NET 4 and AJAX

Visual Studio 2010and

.NET Framework 4

Training Workshop

Visual Studio 2010and

.NET Framework 4

Training Workshop

Page 2: ASP.NET 4 and AJAX

What’s New InASP.NET AJAX 4What’s New InASP.NET AJAX 4

NameTitleOrganizationEmail

Page 3: ASP.NET 4 and AJAX

AgendaAgenda

• Client-Side Templates• Client Controls• Declarative Instantiation• Command Bubbling• Live Bindings

Page 4: ASP.NET 4 and AJAX

“ASP.NET AJAX is alright, but it is way too server-centric for serious client-side development…”

- Uninformed Guy

Page 5: ASP.NET 4 and AJAX

Common MythsCommon Myths

ASP.NET AJAX is tied to ASP.NET, namely WebForms…

You must use a ScriptManager and UpdatePanels to get anything done…

It requires Visual Studio to work…

Page 6: ASP.NET 4 and AJAX

RequirementsRequirements

In order to seriously use ASP.NET AJAX, some need…

1.Client-side controls2.Data binding3.UI templating4.Easy service communication5.Modular functionality

Page 7: ASP.NET 4 and AJAX

Why do some find JavaScript painful?Why do some find JavaScript painful?

Page 8: ASP.NET 4 and AJAX

Who in their right mind wants to do manual XMLHttpRequest work, HTML generation, or data wireup?

Page 9: ASP.NET 4 and AJAX

Server vs. Client AJAXServer vs. Client AJAX

Initial request: HTML

Initial request: HTML

HTMLHTMLForm POSTForm POST

HTML + JSONHTML + JSON

JSONJSONJSONJSON

Renderin

g

Renderin

g

Server AJAX

Client AJAX

Page 10: ASP.NET 4 and AJAX

The server should only be concerned with data, not presentation

Page 11: ASP.NET 4 and AJAX

Client TemplatesClient Templates

Server-Side (WebForms):

<ItemTemplate> <li><%# Eval("Name") %></li>

</ItemTemplate>

Client-Side:

<ul class="sys-template"> <li>{{ Name }}</li>

</ul>

Page 12: ASP.NET 4 and AJAX

Client ControlsClient Controls

DataView DataContext

• Dynamic UI• Master/Detail• DataContext

integration• Select command

bubbling• Etc.

• Server communication• WCF• ASMX

• ADO.NET Data Services• Etc.

• Change tracking• Etc.

Page 13: ASP.NET 4 and AJAX

DataContextDataContext

ASMX

WCF

ADO.NETData Services

ASP.NET MVCJsonResult

Etc.

1. Request

2. JSON DataData

Context

3. Modify Data 4. Save Data

* DataContext includes change tracking automatically

Page 14: ASP.NET 4 and AJAX

Client TemplatesDataViewDataContext

Client TemplatesDataViewDataContext

Page 15: ASP.NET 4 and AJAX

Maybe you’d prefer to write as little JavaScript as possible…

Page 16: ASP.NET 4 and AJAX

Declarative InstantiationDeclarative Instantiation

1. Map:

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

2. Attach:

<div sys:attach="dataview"></div>

3. Use:

<div … dataview:serviceuri="myService.svc"…>

Page 17: ASP.NET 4 and AJAX

Did I mention that it is XHTML compliant?

Page 18: ASP.NET 4 and AJAX

Declarative InstantiationDeclarative Instantiation

Page 19: ASP.NET 4 and AJAX

Command BubblingCommand Bubbling

Server-Side (WebForms):

<asp:Button runat=“server” CommandName=“Select" … />

Client-Side:

<button sys:command="select" … />

Page 20: ASP.NET 4 and AJAX

Live BindingsLive Bindings

Object #1

Property #1Property #2Property #3

Object #2

Property #1Property #2Property #3

Source Target

• One-Time• One-Way• Two-Way

Page 21: ASP.NET 4 and AJAX

Command BubblingLive BindingsChange Tracking

Command BubblingLive BindingsChange Tracking

Page 22: ASP.NET 4 and AJAX

SummarySummary

• Client-Side Templates• Client Controls• Declarative Instantiation• Command Bubbling• Live Bindings

Page 23: ASP.NET 4 and AJAX