Code
<% @ Page Language = "C #" %>
<Script runat = "server">
Protected void Page_Load (object sender, EventArgs e)
{
// Get the candidate user name.
String candidateUserName = Request ["UserName"];
// Validate
Bool isValid = false;
If (candidateUserName. ToLower ()! = "Dflying ")
{
IsValid = true;
}
// Send out result
Response. Clear ();
Response. Write (isValid? "True": "false ");
Response. Flush ();
Response. Close ();
}
</Script>
Code
// JScript File
Function $ (id)
{
Return document. getElementById (id );
}
// Create an xmlhttp object
Function createXmlHttp ()
{
Var xmlHttp;
// Check the MSXMLHTTP version. To be compatible with IE versions
Var activeKey = new Array ("MSXML2.XMLHTTP. 5.0", "MSXML2.XMLHTTP. 4.0", "MSXML2.XMLHTTP. 3.0", "MSXML2.XMLHTTP", "Microsoft. XMLHTTP ");
If (window. ActiveXObject)
{
For (var I = 0; I <activeKey. length; I ++)
{
Try
{
XmlHttp = new ActiveXObject (activeKey [I]);
If (xmlHttp! = Null)
Return xmlHttp;
}
Catch (error)
{
Throw new Error ("your browser version is too low, please update your browser ");
}
}
}
Else if (window. XMLHttpRequest)
{
XmlHttp = new XMLHttpRequest ();
}
Return xmlHttp;
}
Function CheckUserName (name, alertstr)
{
$ ("Checkname"). innerHTML = "loading .";
Var url = "../test/Server. aspx? Action = CheckUserName ";
Var xmlhttp = createXmlHttp ();
Xmlhttp. onreadystatechange = function ()
{
If (xmlhttp. readyState = 4 & xmlhttp. status = 200)
{
Alert (xmlhttp. responseText );
$ ("Checkname"). innerHTML = "yes ";
$ ("Checkname"). innerHTML = "1" + xmlhttp. responseText;
}
}
Xmlhttp. open ("GET", url, true );
Xmlhttp. send (null );
/*
*/
}