利用c#制作简单的留言板(2)

myconn.cs
namespace notpage
{
using System;
using System.Data.SQL ;

 1<p> /// <summary>   
 2/// Summary description for myconn.   
 3/// </summary>   
 4public class myconn:System.Data.SQL.SQLConnection   
 5{   
 6private void InitializeComponent ()   
 7{   
 8}   
 9  
10public myconn()   
11{   
12//   
13// TODO: Add Constructor Logic here   
14//   
15this.Database = "back" ;   
16this.DataSource = "LUOCHANG" ;   
17this.UserID = "sa" ;   
18this.Password = "" ;   
19}   
20}   
21}   
22添加留言addTopic.aspx   

@ Page language="c#" Codebehind="AddTopic.cs" AutoEventWireup="false" Inherits="notpage.AddTopic"

 1<html><head>
 2<meta content="Microsoft Visual Studio 7.0" name="GENERATOR"/>
 3<meta content="C#" name="CODE_LANGUAGE"/></head>
 4<body>
 5<form method="post" runat="server">
 6<table border="0" cellpadding="1" cellspacing="1" width="88%">
 7<tr>
 8<td>留言主题:</td>
 9<td><asp:textbox columns="65" id="txtTitle" maxlength="80" runat="server"></asp:textbox></td></tr>
10<tr>
11<td>姓名:</td>
12<td><asp:textbox columns="20" id="txtAuthor" maxlength="40" runat="server"></asp:textbox></td></tr>
13<tr>
14<td>留言内容</td>
15<td><asp:textbox columns="50" id="txtContent" maxlength="2000" rows="20" runat="server" textmode="MultiLine"></asp:textbox><asp:button id="btnSubmit" runat="Server" text="确认"></asp:button></td></tr></table></form>
16</body></html></p>
 1<p>对应的cs   
 2namespace notpage   
 3{   
 4using System;   
 5using System.Collections;   
 6using System.ComponentModel;   
 7using System.Data;   
 8using System.Drawing;   
 9using System.Web;   
10using System.Web.SessionState;   
11using System.Web.UI;   
12using System.Web.UI.WebControls;   
13using System.Web.UI.HtmlControls;</p>
 1<p> /// <summary>   
 2/// Summary description for AddTopic.   
 3/// </summary>   
 4public class AddTopic : System.Web.UI.Page   
 5{   
 6protected System.Web.UI.WebControls.TextBox txtContent;   
 7protected System.Web.UI.WebControls.TextBox txtAuthor;   
 8protected System.Web.UI.WebControls.TextBox txtTitle;   
 9protected System.Web.UI.WebControls.Button btnSubmit;   
10  
11public AddTopic()   
12{   
13Page.Init += new System.EventHandler(Page_Init);   
14}</p>
1<p> protected void Page_Load(object sender, EventArgs e)   
2{   
3if (!IsPostBack)   
4{   
5//   
6// Evals true first time browser hits the page   
7//   
8}   
9}</p>
1<p> protected void Page_Init(object sender, EventArgs e)   
2{   
3//   
4// CODEGEN: This call is required by the ASP+ Windows Form Designer.   
5//   
6InitializeComponent();   
7}</p>
 1<p> /// <summary>   
 2/// Required method for Designer support - do not modify   
 3/// the contents of this method with the code editor.   
 4/// </summary>   
 5private void InitializeComponent()   
 6{   
 7btnSubmit.Click += new System.EventHandler (this.OnSubmit);   
 8this.Load += new System.EventHandler (this.Page_Load);   
 9}   
10public void OnSubmit(Object sender , EventArgs e)   
11{   
12  
13  
14if (Page.IsValid)   
15{   
16//数据入库   
17try   
18{   
19  
20notepage objNp = new notepage();   
21objNp.Title = txtTitle.Text;   
22objNp.Author = txtAuthor.Text;   
23objNp.Content = txtContent.Text;   
24objNp.adddate = System.DateTime.Now;   
25notepage objNp1 = new notepage();   
26if(objNp1.AddTopic(objNp))   
27{   
28  
29Response.Write ("<p align="center" class="cn">成功留言,点击<a href="list.aspx">此处</a>查看留言列表!。</p>") ;   
30}   
31}   
32catch(Exception exp)   
33{   
34#if DEBUG   
35Response.Write ("出现异常:" + exp.Message) ;   
36return ;   
37#endif//DEBUG   
38  
39}   
40}   
41  
42  
43}</p>
1<p> }   
2}</p>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus