First, add an HTML page. Code As follows: < Html >
< Head >
< Title > The first Ajax small in ASP. NETProgram </ Title >
< Link REL = "Stylesheet" Type = "Text/CSS" Href = "../CSS/main.css" />
< Script Language = "JavaScript" >
VaR XMLHTTP
Function Showhint (STR)
{
If (Str. Length > 0 )
{
VaR URL = " Getrequest. aspx? Name = " + Str
If (Window. activexobject) {< br> XMLHTTP = New activexobject ( " Microsoft. XMLHTTP " );
}
XMLHTTP. onreadystatechange = Statechanged
XMLHTTP. Open ( " Post " , URL, True )
XMLHTTP. Send ( Null )
}
Else
{
Document. getelementbyid ("Txthint"). Innerhtml=""
}
}
Function Statechanged ()
{
If (XMLHTTP. readystate = 4 | XMLHTTP. readystate = " Complete " )
{
Document. getelementbyid ("Txthint"). Innerhtml=XMLHTTP. responsetext
}
}
</ Script >
</ Head > < Body >
< Div Class = Content >
< H1 > Small programs implemented by pure Ajax </ H1 >
< Form >
< P > Enter a string: < Input Type = "Text" ID = "Txt1" Onkeyup = "Showhint (this. Value )" > </ P >
< P >
String Length: < Span ID = "Txthint" > </ Span > </ P >
</ Form > </ Div > </ Body >
</ Html >
Getrequest. aspx? Name = "+ STR indicates that the request page is getrequest. aspx and pass the user-input string to the getrequest page. aspx, so the next step is to create getrequest. the ASPX page calculates the string length. The background code is as follows: 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 Pureajax_getrequest: system. Web. UI. Page
{
Protected Void Page_load ( Object Sender, eventargs E)
{
If (Request. querystring [ " Name " ] ! = "" )
Response. Write (request. querystring [ " Name " ]. Length );
Else
Response. Write ( " Null " );
}
}