完整的登录、注册页面

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

<!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;
            padding: 0px;
        }

        #bz
        {
            height: 700px;
            width: 70%;
            top: 0px;
            left: 0px;
            position: absolute;
            background-image: url(bg32.jpg);
            background-repeat: no-repeat;
            background-size: cover;
        }

        #by
        {
            height: 700px;
            width: 30%;
            top: 0px;
            right: 0px;
            position: absolute;
            background-image: url(bg3.jpg);
            background-repeat: no-repeat;
            background-size: cover;
            min-width:400px;
        }

        .kuang
        {
            height: 30px;
            width: 200px;
        }

        .jian
        {
            height: 30px;
            width: 100px;
            font-size: 20px;
        }

        #shuru
        {
            height: 300px;
            width: 80%;
            top: 150px;
            left: 50px;
            position: absolute;
            font-size:20px;
        }
        #Label1
        {
            color:red;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div id="bz">
        </div>
        <div id="by">
            <div id="shuru">
                <h1>用户登录</h1><br />
                用户名:<asp:TextBox ID="TextBox1" runat="server" CssClass="kuang"></asp:TextBox><br /><br />
                密码:&nbsp&nbsp&nbsp&nbsp<asp:TextBox ID="TextBox2" runat="server" CssClass="kuang" TextMode="Password"></asp:TextBox><br /><br />
                &nbsp&nbsp&nbsp&nbsp<asp:Button ID="Button1" runat="server" Text="登录" CssClass="jian" />&nbsp&nbsp&nbsp&nbsp<asp:Button ID="Button2" runat="server" Text="注册" CssClass="jian" /><br />
                <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
            </div>
        </div>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default3 : System.Web.UI.Page
{
    DataClassesDataContext context = new DataClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        Button1.Click += Button1_Click;//确定按钮点击事件
        Button2.Click += Button2_Click;//注册按钮
    }

    void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }

    void Button1_Click(object sender, EventArgs e)
    {
        List<Users> lu = context.Users.ToList();
        foreach( Users u in lu )
        {
            if (TextBox1.Text == u.UseName && TextBox2.Text == u.Pwd)
            {
                Response.Redirect("Default5.aspx");
            }
            else
            {
                Label1.Text = "用户名或密码错误!";
            }
        }
    }
}

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

<!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;
            padding: 0px;
        }

        #bg
        {
            height: 700px;
            width: 100%;
            background-image: url("bgimage.jpg");
            background-repeat: no-repeat;
            background-size: cover;
            opacity: 0.8;
            position: relative;
        }

        #zhong
        {
            height: 500px;
            width: 60%;
            top: 150px;
            left: 20%;
            position: absolute;
            background-color: white;
            opacity: 1;
            min-width: 700px;
        }

        #left
        {
            height: 500px;
            width: 50%;
            top: 0px;
            left: 0px;
            position: absolute;
            background-image: url("zuo.jpg");
            background-repeat: no-repeat;
            background-size: cover;
        }

        #right
        {
            height: 500px;
            width: 50%;
            top: 0px;
            right: 0px;
            position: absolute;
            background-image: url("you.jpg");
            background-repeat: no-repeat;
            background-size: cover;
        }

        .zhuce
        {
            font-size: 20px;
            margin-left: 60px;
            color: orangered;
        }

        #Label1 Label2
        {
            font-size: 12px;
            color: red;
        }

        #Label2
        {
            font-size: 12px;
            color: red;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div id="bg">
            <div id="zhong">
                <div id="left">
                </div>
                <div id="right">
                    <br />
                    <br />
                    <div class="zhuce">
                        <h1>用户注册</h1>
                    </div>
                    <br />
                    <div class="zhuce">用户名:&nbsp&nbsp&nbsp&nbsp<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Label ID="Label2" runat="server" Text=""></asp:Label></div>
                    <br />
                    <div class="zhuce">密码:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox></div>
                    <br />
                    <div class="zhuce">确认密码:<asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox>
                        <asp:Label ID="Label1" runat="server" Text=""></asp:Label></div>
                    <br />
                    <div class="zhuce">昵称:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></div>
                    <br />
                    <div class="zhuce">
                        性别:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
                            <asp:ListItem Selected="True"></asp:ListItem>
                            <asp:ListItem></asp:ListItem>
                        </asp:RadioButtonList>
                    </div>
                    <br />
                    <div class="zhuce">生日:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList><asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList><asp:DropDownList ID="DropDownList3" runat="server"></asp:DropDownList></div>
                    <br />
                    <div class="zhuce">民族:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<asp:DropDownList ID="DropDownList4" runat="server"></asp:DropDownList></div>
                    <br />
                    <div class="zhuce">
                        <asp:Button ID="Button1" runat="server" Text="注册" ForeColor="#ff6600" Font-Size="20px" Width="100px" Height="40px" /><asp:Label ID="Label3" runat="server" Text=""></asp:Label></div>
                    
                </div>

            </div>

        </div>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{

    DataClassesDataContext context = new DataClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        Button1.Click += Button1_Click;//注册按钮点击事件

        if (IsPostBack == false)
        {
            xunhuan(1900, 2016, DropDownList1);
            xunhuan(1, 12, DropDownList2);
            xunhuan(1, 31, DropDownList3);
        }
        foreach (ListItem li in DropDownList1.Items)
        {
            if (li.Text == "1980")
            {
                li.Selected = true;
            }
        }

        List<Nations> Nalist = context.Nations.ToList();

        //foreach( Nations nt in Nalist )
        //{
        //    ListItem li = new ListItem(nt.NationName,nt.NationCode);
        //    DropDownList4.Items.Add(li);
        //}
        DropDownList4.DataSource = Nalist;
        DropDownList4.DataTextField = "NationName";
        DropDownList4.DataValueField = "NationCode";
        DropDownList4.DataBind();



    }

    void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text == "")
        {
            Label2.Text = "用户名不能为空!";
            return;
        }

        if (TextBox2.Text == "" && TextBox3.Text == "")
        {
            Label1.Text = "密码不能为空!";
            return;
        }
        else if (TextBox2.Text.Trim() != TextBox3.Text.Trim())
        {
            Label1.Text = "两次密码输入不一致!";
            return;
        }

        Users u = new Users();
        u.UseName = TextBox1.Text.Trim();
        u.Pwd = TextBox2.Text.Trim();
        u.NateName = TextBox4.Text.Trim();
        u.Sex = RadioButtonList1.Items[0].Selected;
        u.Birthday = Convert.ToDateTime(DropDownList1.Text + "-" + DropDownList2.Text + "-" + DropDownList3.Text);
        u.Nation = DropDownList4.SelectedValue;
        try
        {
            context.Users.InsertOnSubmit(u);
            context.SubmitChanges();
            Label3.Text = "注册成功!";
        }
        catch
        {
            Label3.Text = "注册失败!";
        }
     

    }

    //循环添加数据
    public void xunhuan(int a, int b, DropDownList c)
    {
        for (int i = a; i <= b; i++)
        {
            ListItem li = new ListItem();
            li.Text = i.ToString();

            c.Items.Add(li);
        }

    }

}

转载于:https://www.cnblogs.com/fengsantianya/p/5680954.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值