码迷,mamicode.com
首页 > Web开发 > 详细

Asp.Net中Ajax实现登陆判断

时间:2016-02-22 17:44:46      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

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==4&&xmlhttp.status==200)
        {
            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("用户名或密码错误!");
            }
        }
    }

  

 

Asp.Net中Ajax实现登陆判断

标签:

原文地址:http://www.cnblogs.com/yuhuameng/p/5207683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!