Professional Documents
Culture Documents
Introducing the
Advanced Ajax And Ajax.Net
Control Toolkit for Asp.NET
Server Responding to
JAVASCRIPT Asynchronous.
JAVASCRIPT updating client.
XmlHttpRequest
Introduced in 1999 with Internet Explorer 5
– ActiveX object supporting callbacks to Web server
– Created for benefit of Outlook Web Access (OWA)
Later adopted by Firefox, Safari, and others
– Implemented as native object rather than ActiveX
– Currently being standardized by W3C
http://www.w3.org/TR/XMLHttpRequest/
Supported by approx. 99% of browsers used
today
– Approx. 85%-95% have JavaScript enabled
Object Instantiation.
function getobject(){
var reqst = false;
try{
reqst = new XMLHttpRequest();
}
catch(msnew){
try{
reqst = new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch(msother){
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (failed) {
request = false;
}
}}}
Methods :
open(); Sets up a new request to a server.
send(); Send a request on server.
readystate; provides current request State.
responseText; The text server send back by server.
responseXML; The Server generated XML response.
ReadyState :
0: The request is uninitialized (before call open()).
1: The request is set up, but not sent (before call send()).
2: The request was sent and is in process.
3: The request is in process;
4: The response is complete; you can get the server's response and use it.
Call Back method is passed to request object by
assigning the onreadystatechange=“function()”
Open Method :
The request open method takes following Args.
request-type: The type of request to send (Get,Post).
url: The URL to connect to.
asynch: Pass here true/false (true if asynch else false).
username: User name, if authentication required;
password: Password, if authentication required.
For Example : -
– open(“GET”,”/myserver/abc.aspx?p1=” + p1,true);
– open(“POST”,”/myserver/abc.aspx”,true);
Send Method :
The parameter for send method is the data in case of data
sent true post method
– send(vname);
– Else Pass null
– send(null);
Demo
Create Request
<script language="javascript" type="text/javascript">
var request = false;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try { request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}}}
if (!request)
alert("Error initializing XMLHttpRequest!");
function getCustomerInfo() {
var phone = document.getElementById("phone").value;
var url = "/cgi-local/lookupCustomer.php?phone=" + escape(phone);
}
</script>
Open Request
function getCustomerInfo()
{
request.onreadystatechange = updatePage;
request.send(null);
}
When to process Request
•Do processing of call back method when: -
•Readystate =4;
•Status = 200;
Example: --------------------------------------------------------------------
------------------------------ function updatePage() {
Client Script
Library
ASP.NET AJAX Server Extensions
Controls, App Services
Components Bridge
ASP.NET AJAX
Component Model Server Controls
Web Services
and UI Framework Bridge
Base Class Library
Client ASP.NET 2.0
Application Script Core
Services Page, Application
Framework, Services
Browser Browser
Server controls
Integration Compatibility
ScriptManager- DragOverlay-
UpdateProgress
Proxy Extender
Timer
ScriptManager- One per page to support AJAX features
ScriptManagerProxy - Use when a .master contains a ScriptManager
already
UpdatePanel - Allows partial-page updates
Timer - Raises event at regular interval
UpdateProgress - Send progress messages back to page
<script src="/.../WebResource.axd?d=iQ15p6LHcT2T5QE..."
type="text/javascript"></script>
<cc1:MyExtender
ExtenderControlBase
this._myStringPropValue = null; runat=“server”
{ this._myStringIntValue
MyExtender TargetControlID=“TextBox1”
=ex1
0; = new MyExtender();
}
[ExtenderProperty]= “Hello”;
ex1.MyStringProp MyStringProp=“Hello”
public string MyStringProp{}
MyProject.MyBehavior.prototype = {
initialize function()MyIntProp=“23”
ex1.MyIntProp { … }, = 23;
ex1.TargetControlID
get_MyStringProp : function(){},
</cc1:MyExtender>
[ExtenderProperty]
set_MyStringProp : function(value){},
= “TextBox1”;
Page.Add(ex1);
public int MyIntProp{}
get_MyIntProp : function(){},
} set_MyIntProp : function(value){}
}
Creating an Extender Project
Toolkit package has Visual Studio templates
for: • Toolkit-enabled website
• Toolkit component project
• Toolkit Components
• VB & C# for each
Summary / Call to Action
AJAX = Asynchronous JavaScript and XML
– Better, richer, and more interactive Web apps
ASP.NET AJAX = Framework for AJAX
development
– Microsoft AJAX Library (client-side framework)
– ASP.NET 2.0 AJAX Extensions (server-side
framework)
ASP.NET AJAX is…
– Compact and well factored (minimal download size)
– Compatible with a wide range of browsers
– Compatible with PHP, ColdFusion, and other
platforms
ASP.NET AJAX is the future
Resources
AJAX Wikipedia entry
– http://en.wikipedia.org/wiki/AJAX
ASP.NET AJAX Web sites
– http://ajax.asp.net
– http://ajax.asp.net/ajaxtoolkit
– www.ajaxwebwidgets.com
– http://www.asp.net/AJAX
– http://forums.asp.net/default.aspx?GroupID=34
– http://asp.net/AJAX/Documentation/Live/ClientReference/