Top Banner
Server Centric Ajax Development with Atlas Brian Johnston, MCP Brian C. Lanham, MCP (.NET) November 2006
35
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: rvnug.org

Server Centric Ajax Developmentwith Atlas

Brian Johnston, MCP

Brian C. Lanham, MCP (.NET)

November 2006

Page 2: rvnug.org

Agenda

• What is AJAX and Why is it Important

• How to Use AJAX

• When and Where to Use AJAX

Page 3: rvnug.org

Web Application Architecture

• Web Browser Posts Request to Web Server

• Web Server Responds to Request and Sends Response to Web Browser

• User Makes Additional Requests Based on Data

• Cycle Repeats

Page 4: rvnug.org

ASP.NET Web Development

• ASP.NET Significantly Eases Our Jobs

• The Robust Technology Translates to More Robust Web Applications

• Consistency is Improved, Allowing Us to Build Larger Applications

• Resource Management and Internationalization Support Means a Broader Audience

Page 5: rvnug.org

Problems with Today’s Web Apps

• Users Have Many (often Interrelated) Features, Available on a Single Page

• Ever-Increasing Amounts of Information are Sent to the Users

• Users Continue to Increase the Amount of Storage they Consume

• Web Applications are MUCH More Complex

Page 6: rvnug.org

Row you lazy dogs! Greeks are dying!(or “Ajax to the Rescue”)

• Number of Round Trips

• Bandwidth

• Latency

• Performance

• General User Experience

Page 7: rvnug.org

AJAX in Context

• AJAX is NOT specific to .NET

• AJAX can be thought of as a “Mini Web Browser…Exactly like the real Web browser in every way except 1/3 the size.”

• Microsoft’s Implementation of AJAX for the .NET platform is called “ASP.NET AJAX”

• ASP.NET 2.0 Supports AJAX as do MANY Vendor Controls

Page 8: rvnug.org

Using AJAX – Conceptually

• XmlHttpRequest Object

• JavaScript

• DHTML & Document Object Model (DOM) Support

• XML Data Transport

Page 9: rvnug.org

ASP.NET AJAX Server Controls

Goal: Easily enhance any ASP.NET web applicationApplication UI and core logic still runs on serverAvoid need to master JavaScript and asynchronous programming

Use AJAX techniques to reduce roundtripsEnable incremental page UI updates (avoid full page refreshes)Scenarios: data navigation and editing, form validation, auto refresh

Enable richer interactivity for existing ASP.NET controlsUse the same controls, object model and events you already knowExtenders to add AJAX behaviors to any ASP.NET controlsExamples: auto-completion, web-parts, drag-and-drop, tooltips

New, richer ASP.NET server controlsServer wrappers for AJAX client controlsExamples: DateTimePicker, RichTextBox, Re-Order List

Page 10: rvnug.org

<atlas:updatepanel> control

Container control that enables “updatable” regions in a pageAtlas provides a XmlHttp based postback infrastructure

Some non-updatable content and controls...

<asp:UpdatePanel id=“u1” runat=“server”> <ContentTemplate>

This content can be dynamically updated!

<asp:label id="Lablel1” runat=“server”/> <asp:button id=“button1” text=“Push Me!” runat=“server”/>

<ContentTemplate></asp:UpdatePanel>

More non-updatable content and controls...

Page 11: rvnug.org

Simple UpdatePanel Demo

Page 12: rvnug.org

<asp:UpdatePanel> Under the Covers

AJAX intercepts post-back submit actions on client

Uses XMLHttp to fire postback action to server

Postback events fire like normal on server

Only content of updatepanel regions returned

Changed updatepanel regions replaced on client

Page 13: rvnug.org

<asp:UpdatePanel> Postbacks

All post-back actions for controls declared within an updatepanel control will cause Ajax-based post-backs with incremental page refresh

Post-back action for controls outside of an updatepanel control will by default cause normal postbacks

Page 14: rvnug.org

<asp:UpdatePanel> Postbacks

‘ the below button will cause a normal full-page postback and update<asp:button id=“NormalPostBack” onclick=“btn1_click” runat=“server”/>

<asp:UpdatePanel id=“u1” runat=“server”> <ContentTemplate>

Updatable content...

‘ the below button will cause an Ajax postback and refresh <asp:button id=“AjaxPostback” onclick=“btn2_click” runat=“server”/>

</ContentTemplate></asp:UpdatePanel>

Page 15: rvnug.org

<asp:UpdatePanel> Triggers

Triggers can be used to associate UpdatePanels on the page with postback controls declared outside of the UpdatePanel

<asp:ControlEventTrigger>Refresh the UpdatePanel when a control event fires

<asp:ControlValueTrigger> Update the UpdatePanel when a control value changes

Page 16: rvnug.org

<asp:UpdatePanel> Triggers

<asp:button id=“AjaxPostback” onclick=“btn1_click” runat=“server”/>

<asp:UpdatePanel id=“u1” runat=“server”> <ContentTemplate>

This content will be updated when a button is clicked outside of the UpdatePanel contentemplate...

</ContentTemplate>

<Triggers> <asp:ControlEventTrigger controlId=“AjaxPostBack” EventName=“Click”/> </Triggers>

</asp:UpdatePanel>

Page 17: rvnug.org

UpdatePanel with Triggers

Page 18: rvnug.org

<asp:UpdatePanel> Refresh Modes

Multiple UpdatePanel Controls can be added to a pageSometimes you only want to update one panel…

UpdatePanel control supports two update modes:“Always” = Refresh every-time an Ajax postback occurs“Conditional” = Refresh when specific Ajax postback occurs

Conditional refreshes can be done via triggers:<asp:ControlEventTrigger> -- Update on control event fires<asp:ControlValueTrigger> -- Update when value changes

Conditional refreshes can also be triggered via code:UpdatePanel1.Update() method causes that panel to refresh

Page 19: rvnug.org

<asp:UpdatePanel> Refresh Modes

<asp:button id=“AjaxPostback” onclick=“btn1_click” runat=“server”/><asp:textbox id=“TextBox1” runat=“server”/>

<asp:UpdatePanel id=“u1” mode=“Conditional” runat=“server”> <ContentTemplate>

This content will only be updated when a button is clicked outside of the UpdatePanel contentemplate, or if the TextBox1.Text property changes

</ContentTemplate>

<Triggers> <asp:ControlEventTrigger controlId=“AjaxPostBack” EventName=“Click” /> <asp:ControlValueTrigger controlId=“TextBox1” PropertyName=“Text”/> </Triggers>

</asp:UpdatePanel>

Page 20: rvnug.org

Conditional UpdatePanel Demo

Page 21: rvnug.org

<asp:UpdateProgress> control

Delivers ability to provide “status” UI while waiting on response from a server

Remember that “A” in “Ajax” stands for AsynchronousNeed to provide way for users to understand latencyNeed to provide way for users to cancel requests

UpdateProgress control can be placed anywhere on pageTemplated control allows any content (e.g. animated .gif)Can use CSS to position/style anywhere

Page 22: rvnug.org

<asp:UpdateProgress> control

<asp:UpdatePanel id=“u1” mode=“Conditional” runat=“server”> <ContentTemplate> <asp:gridview id=“GridView1” runat=“server”> ... </asp:gridview> </ContentTemplate>

</asp:UpdatePanel>

<asp:UpdateProgress>

<ProgressTemplate> <div class="updateprogress"> <img src="images/progress_animation.gif" /> Updating... </div> </ProgressTemplate>

</asp:UpdateProgress>

Page 23: rvnug.org

<asp:UpdateProgress> control

<asp:UpdateProgress>

<ProgressTemplate> <div class="updateprogress">

<img src="images/progress_animation.gif" /> Updating... <asp:linkbutton id=“abortButton” text=“Cancel” runat=“server”/>

</div> </ProgressTemplate>

</asp:UpdateProgress>

Page 24: rvnug.org

UpdateProgress Demo

Page 25: rvnug.org

<asp:TimerControl>

<asp:TimerControl> is a simple control that can be used to refresh updatepanel controls based on time duration

Page 26: rvnug.org

<asp:TimerControl>

<asp:TimerControl ID="Timer1" runat="server" Enabled="true" Interval="5000" OnTick="UpdateTimestamp“/>

This page will update with the server timestamp every 5 seconds.

<asp:UpdatePanel ID="upanel" runat="server"> <ContentTemplate> <asp:Label ID="Timestamp" runat="server"></asp:Label> </ContentTemplate>

<Triggers> <atlas:ControlEventTrigger ControlID="Timer1" EventName="Tick"/> </Triggers></asp:UpdatePanel>

Page 27: rvnug.org

TimerControl Demo

Page 28: rvnug.org

<asp:AutoCompleteExtender>

Enables textbox auto-complete supportCallback to web-service on server for word listSupports both .asmx and WCF based web-services (both using the built-in Atlas JSON bridge)

Useful example of “extender” controlsExtenders allow pointing to existing server controls

Other “extender” controls that are being planned: Watermark, popup, drag/drop, masked edit, date-time picker, tool tips, etc.

Page 29: rvnug.org

<asp:AutoCompleteExtender>

<asp:textbox id=“CustomerSearch” runat=“server”/>

<asp:AutoCompleteExtender ID="AutoComplete" runat="server">

<asp:AutoCompleteProperties Enabled="true" ServiceMethod="GetCustomerName" ServicePath="~/CustomerService.asmx" TargetControlID="CustomerSearch" />

</asp:AutoCompleteExtender>

Page 30: rvnug.org

<asp:AutoCompleteExtender>

public class CustomerSearch : System.Web.Services.WebService {

[WebMethod] public string[] GetCustomerName(string prefixText, int count) { // todo: take prefixText and generate suggestion list }}

Page 31: rvnug.org

AutoCompleteExtender Demo

Page 32: rvnug.org

Oh Boy! Where do I start?

• AJAX is NOT a Panacea• Performance is still an issue

• AJAX is NOT Significantly Architectural• You Can Refactor to Implement it after the Initial

Release

• AJAX is Generally NOT Supported on Down-Level (Mobile) Browsers

Page 33: rvnug.org

Aw Dad! So When Can I Play?

• Status Areas & Long-Running Processes

• Simple Feedback Forms

• Large Amounts of (Hierarchical) Data

• Sit-Rep Panels

• Auto-Save Features

Page 35: rvnug.org

Thank You for Attending!