Dynamically display the number of strings in the text box (Ajax entry applet)

Source: Internet
Author: User

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 " );
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.