<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body style="font-weight: 700">
<form id="form1" runat="server">
<div>
<table style="width:600px;">
<tr>
<td>
主题:
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Width="638px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
姓名:
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" Width="638px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
内容:
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" Height="322px" Width="634px">
</asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" Text="提交" οnclick="Button1_Click" />
<asp:LinkButton ID="LinkButton1" runat="server" οnclick="LinkButton1_Click">显示留言</asp:LinkButton>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
String DBConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection Con = new SqlConnection();
Con.ConnectionString = DBConnString;
Con.Open();
string cmd = "insert into [liuyanban1] (Name,title,content,Time) values ('" +TextBox1.Text + "','" + TextBox2.Text + "','"+TextBox3.Text + "','" + DateTime.Now.ToString() + "')";
SqlCommand Com = new SqlCommand(cmd, Con);
Com.ExecuteNonQuery();
Con.Close();
Response.Write("<script>alert('" + "添加成功" + "');</script>");
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Default2.aspx");
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html x