Page code:
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
<SCRIPT type = "text/JavaScript">
Function $ (e ){
Return document. getelementbyid? Document. getelementbyid (e): NULL;
}
Function check (name ){
VaR XMLHTTP = false;
VaR url = "handler1.ashx? Name = "+ name +" & RD = "+ math. Random ();
Createxmlhttp ();
Ajax_process (URL );
}
Function ajax_process (URL ){
XMLHTTP. Open ("Post", URL, true );
XMLHTTP. onreadystatechange = ajax_sumbitemployment;
XMLHTTP. Send (null );
Function ajax_sumbitemployment (){
If (XMLHTTP. readystate = 4 ){
If (XMLHTTP. Status = 200 ){
If (XMLHTTP. responsetext = "validatenull "){
$ ('Label1'). innertext = "the user name cannot be blank! ";
Return;
}
If (XMLHTTP. responsetext = "smalllength "){
// $ ('Label1'). innertext = "cannot be less than 2 Characters! ";
Alert ("5432323 ");
Return;
}
If (XMLHTTP. responsetext = "exist "){
$ ('Label1'). innertext = "the user name already exists. Please select another user name! ";
Return;
}
Else {
$ ('Label1'). innertext = "Congratulations, you can use the user name! ";
}
}
}
}
}
// Create an Ajax object
Function createxmlhttp (){
Try {XMLHTTP = new activexobject ("msxml2.xmlhttp ");}
Catch (e ){
Try {XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");}
Catch (e ){
Try {XMLHTTP = new XMLHttpRequest ();}
Catch (e) {XMLHTTP = false ;}
}
}
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: Label id = "label1" runat = "server" text = "label"> </ASP: Label>
<Asp: textbox id = "txtusernaem" runat = "server" onblur = "Return check (this. Value)"> </ASP: textbox>
<Asp: textbox id = "textbox1" runat = "server"> </ASP: textbox>
</Div>
</Form>
</Body>
</Html>
Processing file: handler1.ashx
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
string Name = context.Request.QueryString["Name"];
if (!String.IsNullOrEmpty(Name))
{
if (Name.Length < 2)
{
context.Response.Write("smallLength");
}
else
{
context.Response.Write("exist");
}
// Maticsoft.BLL.Personnel person = new Maticsoft.BLL.Personnel();
// Maticsoft.Model.personnelDate personDate = person.GetModel(Name);
//if (personDate != null)
//{
// context.Response.Write("exist");
//}
}
else
{
context.Response.Write("validateNull");
}
}
public bool IsReusable
{
get
{
return false;
}
}
}