Asp.Net中Ajax实现登陆判断

Default.aspx:

<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
var xmlhttp;
function Login()
{
var userName=document.getElementById("TextBox1").value;
var userPwd=document.getElementById("TextBox2").value;
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET","Login.aspx?UserName="+userName+"&UserPwd="+userPwd,true);
xmlhttp.onreadystatechange=stateChange;
xmlhttp.send(null);
return false;
} function stateChange()
{
if(xmlhttp.readystate==&&xmlhttp.status==)
{
document.getElementById("Label1").innerHTML=xmlhttp.responseText;
}
}
</script> </head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Width="100px"></asp:TextBox><br />
<asp:TextBox ID="TextBox2" runat="server" Width="100px"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="登陆" />
<asp:Label ID="Label1" runat="server"></asp:Label></div>
</form>
</body>
    protected void Page_Load(object sender, EventArgs e)
{
this.Button1.Attributes.Add("OnClick","return Login()");
}
Login.aspx:

    protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["UserName"] != null && Request.QueryString["UserName"].Length != 0 && Request.QueryString["UserPwd"] != null && Request.QueryString["UserPwd"].Length != 0)
{
if (Request.QueryString["UserName"] == "wu1987116" && Request.QueryString["UserPwd"] == "wu1987116")
{
Response.Write("登陆成功!");
}
else
{
Response.Write("用户名或密码错误!");
}
}
}

  

上一篇:[ SSH框架 ] Struts2框架学习之三(OGNl和ValueStack值栈学习)


下一篇:Struts2【OGNL、valueStack】就是这么简单