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

20151221:Web复习:登陆

时间:2015-12-24 23:43:01      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

前台HTML代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Denglu.aspx.cs" Inherits="Denglu" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <style type="text/css">

                * {
                    margin: 0px auto;
                    padding: 0px;
                }
     </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="aa" style="width:400px">
        <h1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</h1>
        <h1>&nbsp;</h1>
        <h1>&nbsp;</h1>
        <h1>&nbsp;</h1>
        <h1>&nbsp;</h1>
        <h1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 登录</h1>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label>
        <asp:TextBox ID="txtUid" runat="server"></asp:TextBox>
        <br />
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Label ID="Label2" runat="server" Text="密码:"></asp:Label>
        <asp:TextBox ID="txtPwd" runat="server" TextMode="Password"></asp:TextBox>
        <br />
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button1" runat="server" Text="登陆" OnClick="Button1_Click" />
    
        <asp:Literal ID="Literal1" runat="server"></asp:Literal>
    
    </div>
    </form>
</body>
</html>

后台C#代码:

public partial class Denglu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        TextDataContext context = new TextDataContext();
        //取值
        string uid = txtUid.Text;
        string pwd = txtPwd.Text;
        //查询
        var query = context.login1.Where(p => p.username == uid && p.password == pwd);
        //判断
        if (query.Count() > 0)
        {
            Session["uid"] = uid;
            Response.Redirect("Main.aspx");
        }
        else
        {
            Literal1.Text = "<script type=‘Text/javascript‘>alert(‘用户名或密码错误!‘);</script>";
        }
    }
}

技术分享

20151221:Web复习:登陆

标签:

原文地址:http://www.cnblogs.com/mn-b/p/5074523.html

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