20151223:Web:审核:注册
aspx代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ZhuCe.aspx.cs" Inherits="ZhuCe" %> <!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:358px; } </style> </head> <body> <form id="form1" runat="server"> <div class="dl"> <h1> 注册</h1> <p> <asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" Height="19px"></asp:TextBox> </p> <p> <asp:Label ID="Label2" runat="server" Text="密码:"></asp:Label> <asp:TextBox ID="TextBox2" runat="server" Height="19px"></asp:TextBox> </p> <p> <asp:Label ID="Label3" runat="server" Text="姓名:"></asp:Label> <asp:TextBox ID="TextBox3" runat="server" Height="19px"></asp:TextBox> </p> <p> <asp:Label ID="Label4" runat="server" Text="性别:"></asp:Label> <asp:RadioButton ID="RadioButton1" runat="server" Checked="True" GroupName="Sex" Text="男" /> <asp:RadioButton ID="RadioButton2" runat="server" GroupName="Sex" Text="女" /> </p> <p> <asp:Label ID="Label5" runat="server" Text="生日:"></asp:Label> <asp:TextBox ID="TextBox4" runat="server" Height="19px"></asp:TextBox> </p> <p> </p> <p> <asp:Button ID="Button1" runat="server" Text="注册" OnClick="Button1_Click" /> </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 ZhuCe : 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; string name = TextBox3.Text; bool sex = RadioButton1.Checked; DateTime birthday = Convert.ToDateTime(TextBox4.Text); //造对象 users data = new users(); data.UserName = uid; data.PassWord = pwd; data.Name = name; data.Sex = sex; data.Birthday = birthday; data.State = 0; //添加 context.users.InsertOnSubmit(data); context.SubmitChanges(); } }