1、以下是Register.aspx页面的代码,主要是通过Xmlhttp来向UserIsExist.aspx页面Post要检查的用户名过去。
<form id=Form1 method=post runat="server">
<input id=aa size=66> <input onclick="check();" type="button" value="查看用户是否存在"></form>
<script language="javascript">
<!--
function check()
{
var UserName=document.getElementById("txtName").value;
var user="username="+escape(UserName);
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var xmldoc = new ActiveXObject("Msxml.DOMDocument");
xmlhttp.Open("POST","UserIsExist.aspx",false);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=GB2312");
xmlhttp.Send(user);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
alert(xmlhttp.responseText)
}
}
if(xmlhttp.status!=200)
{
alert ('网络故障(xmlhttp.status='+xmlhttp.status+'),请稍后再试!');
}
else
{
document.getElementById('message').innerHTML = xmlhttp.responseText;
}
}
//-->
</script>2、在UserIsExist.aspx的Page_Load中加入下面代码
string username=Server.UrlDecode(Request.Form["username"].ToString());
if(User.IsExist(username)==true)
{
Response.Write("<font color=red>对不起,你的用户名已被注册过了.</font>");
}
else
{
Response.Write("<font color=red>恭喜您,此用户名还未被使用,你可以继续使用!</font>");
}
<form id=Form1 method=post runat="server">
<input id=aa size=66> <input onclick="check();" type="button" value="查看用户是否存在"></form>
<script language="javascript">
<!--
function check()
{
var UserName=document.getElementById("txtName").value;
var user="username="+escape(UserName);
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var xmldoc = new ActiveXObject("Msxml.DOMDocument");
xmlhttp.Open("POST","UserIsExist.aspx",false);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=GB2312");
xmlhttp.Send(user);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
alert(xmlhttp.responseText)
}
}
if(xmlhttp.status!=200)
{
alert ('网络故障(xmlhttp.status='+xmlhttp.status+'),请稍后再试!');
}
else
{
document.getElementById('message').innerHTML = xmlhttp.responseText;
}
}
//-->
</script>2、在UserIsExist.aspx的Page_Load中加入下面代码
string username=Server.UrlDecode(Request.Form["username"].ToString());
if(User.IsExist(username)==true)
{
Response.Write("<font color=red>对不起,你的用户名已被注册过了.</font>");
}
else
{
Response.Write("<font color=red>恭喜您,此用户名还未被使用,你可以继续使用!</font>");
}