1、以下是1.aspx页面的代码,主要是通过Xmlhttp来向do1.aspx页面Post要检查的用户名过去。
    

<form id=Form1 method=post runat="server">
    <input id=aa style="Z-INDEX: 101; LEFT: 176px; WIDTH: 432px; POSITION: absolute; TOP: 64px; HEIGHT: 24px" size=66> <input style="Z-INDEX: 102; LEFT: 309px; POSITION: absolute; TOP: 111px" onclick=check(); type=button value=查看用户是否存在>
</form>
<script language=javascript>
<!--
function check()
{
var bb=document.getElementById ("aa");
var user="aa="+bb.value;
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var xmldoc = new ActiveXObject("Msxml.DOMDocument");
xmlhttp.Open("POST","do1.aspx",false);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.Send(user);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
alert(xmlhttp.responseText)
}
}
if(xmlhttp.status!=200)
alert ('网络故障(xmlhttp.status='+xmlhttp.status+'),请稍后再试!');
var aaaa = xmlhttp.responseText;
alert(aaaa);
}
//-->
</script>


2、在do1.aspx的Page_Load中加入下面代码(其中ExecuteSql5ValueEx ()方法为执行Sql语句,能查到值时返回True,否则返回False)

   string aa=Request.Form["aa"].ToString ();
   string sql="SELECT username FROM [user] WHERE (username = '"+aa+"')";
   if(ExecuteSql5ValueEx (sql))
   {
         Response.Write ("已经存在该用户!");
   }
   else
   {
        Response.Write ("不存在该用户!");
   }