<%@ 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 />
密码:    <asp:TextBox ID="TextBox2" runat="server" CssClass="kuang" TextMode="Password"></asp:TextBox><br /><br />
    <asp:Button ID="Button1" runat="server" Text="登录" CssClass="jian" />    <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 = "用户名或密码错误!";
}
}
}
}
![](https://images2015.cnblogs.com/blog/943867/201607/943867-20160718134340466-1668657316.png)
![](https://images2015.cnblogs.com/blog/943867/201607/943867-20160718134417669-603227385.png)
<%@ 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">用户名:    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Label ID="Label2" runat="server" Text=""></asp:Label></div>
<br />
<div class="zhuce">密码:        <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">昵称:        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></div>
<br />
<div class="zhuce">
性别:        <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">生日:        <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">民族:        <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://images2015.cnblogs.com/blog/943867/201607/943867-20160718135313591-257190909.png)