.NET注册页面代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void res_btn_Click(object sender, EventArgs e)
{
string Conn = "server=(local);database=YGC;UId=sa;password=sa";
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString); //创建连接查询
conn.Open();
string cmdtext = "insert into account (account,password) values ('" + TextBox1.Text + "','" + TextBox2.Text + "')";
SqlCommand cmd = new SqlCommand(cmdtext, conn);
cmd.ExecuteNonQuery();
Response.Write("<script>alert('注册成功!');window.location.href ='login.aspx'</script>");
conn.Close();
}
}
前端代码:
<%@ 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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="用户名"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1" runat="server" ErrorMessage="用户名不能为空"></asp:RequiredFieldValidator>
<br/>
密 码
<asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="TextBox2"
runat="server" ErrorMessage="密码不能为空"></asp:RequiredFieldValidator>
<br/>
<asp:Button ID="res_btn" runat="server" BorderStyle="None" Height="37px"
Text="注册" Width="115px" onclick="res_btn_Click" />
</div>
</form>
</body>
</html>