• 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>";
            }
        }
    }

  • 相关阅读:
    csu 1141 节能
    WA:ZOJ 1025 Wooden Sticks
    UVa 531 Compromise
    UVa 437 The Tower of Babylon
    UVa 10285 Longest Run on a Snowboard
    在asp.net使用web.config身份验证
    掌握 Ajax,第 6 部分: 建立基于 DOM 的 Web 应用程序
    面向对象编程思想
    一步一步学Remoting之五:异步操作
    Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
  • 原文地址:https://www.cnblogs.com/mn-b/p/5079181.html
Copyright © 2020-2023  润新知