温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:yeal简化留言板源代码(学习版)
当前文件:
531TWIN5UOV431/guestBook.aspx.cs[2K,2009-6-12 11:31:10],打开代码结构图
531TWIN5UOV431/guestBook.aspx.cs[2K,2009-6-12 11:31:10],打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Web; 5
using System.Web.Security; 6
using System.Web.UI; 7
using System.Web.UI.WebControls; 8
using System.Web.UI.WebControls.WebParts; 9
using System.Web.UI.HtmlControls; 10
using System.Data.OleDb; 11
12
public partial class _Default : System.Web.UI.Page 13
{ 14
//downLoad From 51aspx.com 15
protected void Page_Load(object sender, EventArgs e) 16
{ 17
if (!IsPostBack) 18
{ 19
this.clear.CausesValidation = false; 20
this.submit.CausesValidation = false; 21
System.Random rd = new Random(); 22
string rand = Convert.ToString(rd.Next(1000, 9999)); 23
this.validate.Text = rand; 24
} 25
} 26
protected void submit_Click(object sender, EventArgs e) 27
{ 28
if (this.txtValidate.Text == this.validate.Text) 29
{ 30
} 31
else 32
{ 33
this.RequiredFieldValidator2.IsValid = false; 34
} 35
if (this.txtName.Text.Equals("")) 36
{ 37
this.RequiredFieldValidator1.IsValid = false; 38
} 39
if (this.txtContent.Text.Equals("")) 40
{ 41
this.RequiredFieldValidator3.IsValid = false; 42
} 43
if (this.RequiredFieldValidator1.IsValid == true && this.RequiredFieldValidator2.IsValid == true && this.RequiredFieldValidator3.IsValid == true) 44
{ 45
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + 46
System.Web.HttpContext.Current.Server.MapPath("App_Data/db.mdb")); 47
string strIP = Request.ServerVariables["REMOTE_ADDR"].ToString(); 48
string strSQL = "insert into guestBook(gname,gcontent,gIP) values('" + Server.HtmlDecode(this.txtName.Text) + "','" + Server.HtmlDecode(this.txtContent.Text) + "','" + strIP + "')"; 49
OleDbCommand cmd = new OleDbCommand(strSQL, conn); 50
cmd.Connection.Open(); 51
if (cmd.ExecuteNonQuery() > 0) 52
{ 53
Response.Redirect("successful.htm"); 54
} 55
conn.Close(); 56
} 57
58
59
} 60
protected void clear_Click(object sender, EventArgs e) 61
{ 62
this.txtContent.Text = ""; 63
this.txtName.Text = ""; 64
this.txtValidate.Text = ""; 65
} 66
} 67






}
}