Asp.net implements no-refreshing user name Detection

Source: Internet
Author: User
This article will introduce you ASP. NET implements no refreshing detection of user names The function is: when the user enters the user name, the user name text box loses focus, it checks whether the user name is repeated, you do not need to click a button to check the status. (many websites now have this function ).

The following describes how to implement this function.Code:

Front-end code:

The following is a reference clip:

<SCRIPT type = "text/JavaScript" Language = "JavaScript">
VaR XMLHTTP = NULL;
Function checkuser ()
{
Try
{
XMLHTTP = new activexobject ("msxml2.xmlhttp ");
}
Catch (err1)
{
Try
{
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Catch (err2)
{
XMLHTTP = new XMLHttpRequest ();
}
}
VaR text1 = Document. getelementbyid ("text1 ");
VaR url = "chkuser. aspx? User = "+ text1.value;
XMLHTTP. Open ("get", URL, true );
XMLHTTP. onreadystatechange = onhandler;
XMLHTTP. Send (null );

}
Function onhandler ()
{
If (XMLHTTP. readystate = 4)
{
VaR isvalid = XMLHTTP. responsetext;
VaR exists = Document. getelementbyid ("exsits ");
Exists. innerhtml = isvalid. substring (0, 4 );
}
}
</SCRIPT>
<Input id = "text1" type = "text" onblur = "checkuser ()"/> <Label D = "exsits"> </label> <br/>

Create a chkuser. aspx and change the background code:

The following is a reference clip:

Protected void page_load (Object sender, eventargs E)
{
String user = This. Request. querystring ["user"];

If (userexist (User ))
{
Response. Write ("exist ");
}
Else
{
Response. Write ("nonexistent ");
}

}

private bool userexist (string username)
{< br> classlib. employee EMP = new classlib. employee ();
return EMP. empnameexist (username);
}

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.