<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="zhuceyanzheng._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<title>无标题页</title>
</head>
<script type="text/javascript" src="CSS/jquery-1.3.2.js"></script>
<script type="text/javascript">
function JudgeUserName()
{
$.ajax({
type:"GET",
url:"check.aspx",
dataType:"html",
data:"userName="+$("#txtName").val(),
beforeSend:function(XMLHttpRequest)
{
$("#showResult").text("正在查询");
//Pause(this,100000);
},
success:function(msg)
{
$("#showResult").html(msg);
$("#showResult").css("color","red");
},
complete:function(XMLHttpRequest,textStatus)
{
//隐藏正在查询图片
},
error:function()
{
//错误处理
}
});
}
</script>
<body>
<form id="form1" runat="server">
<div>
<input id="txtName" type="text" onblur="JudgeUserName();"/><asp:Label ID="showResult" runat="server"></asp:Label>
</div>
</div>
</form>
</body>
</html>
再建一张check页面,前台只需要保留
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="check.aspx.cs" Inherits="zhuceyanzheng.check" %>
这些
在后台再写
protected void Page_Load(object sender, EventArgs e)
{
try
{
string userName = Request.QueryString["userName"].ToString();
if (userName == "123")
{
Response.Write("用户名已经存在!");
}
else if (userName == "")
{
Response.Write("用户名不能为空!");
}
else
{
Session["username"] = userName;
Response.Write("您可以使用此用户名!");
}
}
catch (Exception)
{
}
}
这样就能无刷新的判断用户名是否存在了