zoukankan      html  css  js  c++  java
  • 20151223:Web:审核:登陆

    aspx代码:

    <%@ 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>
        .dl {
            margin:0px auto;
            padding:0px;
            left:400px;
            width:304px;
            height:257px;
        }
    </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div class="dl">
            <h1>&nbsp;&nbsp;&nbsp; 登录</h1>
            <p>&nbsp;</p>
            <p>
                &nbsp;
                <asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            </p>
            <p>
                &nbsp;&nbsp;
                <asp:Label ID="Label2" runat="server" Text="密码:"></asp:Label>
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Button ID="Button1" runat="server" Text="登陆" OnClick="Button1_Click" />
                <asp:Literal ID="Literal1" runat="server"></asp:Literal>
            </p>
        </div>
        </form>
    </body>
    </html>

    cs代码:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class DengLu : System.Web.UI.Page
    {
        private UsersDataContext context = new UsersDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            //取值
            string uid = TextBox1.Text;
            string pwd = TextBox2.Text;
            //查数据库
            var query = context.users.Where(p => p.UserName == uid && p.PassWord == pwd);
            if(query.Count()>0)
            {
                int state = query.First().State.Value;
                if (state == 0)
                {
                    Literal1.Text = "<script type='Text/javascript'>alert('此账号未审核!');</script>";
                }
                else if(state == 1)
                {
                    Session["uid"] = uid;
                    Response.Redirect("Main.aspx");
                }
                else
                {
                    Literal1.Text = "<script type='Text/javascript'>alert('此账号审核失败!');</script>";
                }         
            }
            else
            {
                Literal1.Text = "<script type='Text/javascript'>alert('用户名或密码错误!');</script>";
            }
        }
    }

  • 相关阅读:
    js上传照片本地预览
    2020年6月23日第一次面试题(外派PA)
    笔记
    2020VUE系统回顾与学习
    2019最全前端面试问题及答案总结
    常见的浏览器兼容性问题总结
    Vue咖啡app项目总结
    跨域问题研究总结
    Class.forName()用法及与new区别
    反射
  • 原文地址:https://www.cnblogs.com/mn-b/p/5079181.html
Copyright © 2011-2022 走看看