Read the example on the website of Okajax, learn Ajax, oneself imitate done, really good, the following his code announced;
First, create a new page, the HTML code to overwrite the original HTML,. cs File No need to thank any code
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default.aspx.cs" Inherits = "_default"%> ;
<! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.1//en" "Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
< html xmlns = "http://www.w3.org/1999/xhtml" >
< head runat = "server" >
< title > Untitled Page </title >
< SCRIPT language = "javascript" type = "Text/javascript" >
var zipfield = null;
function zipchanged () {
Zipfield = document.getElementById ("ZipCode")
var zip = Zipfield.value;
Updatecity (Zip);
}
function updatecity (Zip) {
var Cityfield = document.getElementById ("city");
Ask ("Default2.aspx?") lookuptype=city&zip= "+ Zip,cityfield,zipfield);
}
</script >
< SCRIPT language = "javascript" type = "Text/javascript" >
HttpRequest = function () {
var xmlhttp = null;
try {
XMLHTTP = new ActiveXObject ("Msxml2.xmlhttp");
} catch (_e) {
try {
XMLHTTP = new ActiveXObject ("Microsoft.XMLHTTP");
\ catch (_e) {}
}
if (! XMLHTTP && typeof XMLHttpRequest!= ' undefined ') {
try {
XMLHTTP = new XMLHttpRequest ();
catch (e) {
XMLHTTP = false;
} }
return XMLHTTP;
}
function Ask (URL, Fieldtofill, Lookupfield)
{
var http = new HttpRequest ();
Http.open ("Get", url, True);
Http.onreadystatechange = function ()
{
Handlehttpresponse (http, Fieldtofill, Lookupfield)
}
Http.send (NULL);
}
function Handlehttpresponse (http, Fieldtofill, Lookupfield)
{
if (http.readystate = 4)
{
result = Http.responsetext;
if (-1!= result.search ("null"))
{
LookupField.style.borderColor = "Red";
Fieldtofill.value = "";
}
Else
{
LookupField.style.borderColor = "";
Fieldtofill.value = result;
}
}
}
</script >
< BODY >
< form ID = "Form1" runat = "server" >
Zip Code: < Asp:textbox ID = "ZipCode" runat = "server" onKeyUp = "zipchanged ()" ></Asp:textbox >
Cities: < Asp:textbox ID = "City" runat = "server" ></asp:textbox >& nbsp;
</form >
</Body >
</HTML >
Then in the new page, called Default2.aspx, and then, put the inside except the < @Page > This line does not delete, the other code, all erased
Finally, this. cs file, file cover out your CS file can
Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
public partial class Default2:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
Try
{
String svalue = request.querystring["Zip"]. ToString ();
Switch (svalue)
{
Case "0312":
Response.Write ("Hebei");
break;
Case "010":
Response.Write ("Beijing");
break;
}
}
catch (System.Exception E1)
{
}
}
}
The above is, can test OH.