温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:51aspx修正版简单三层留言板源码
当前文件:
LeaveMessageMVC/LMListForPublic.aspx.cs,打开代码结构图
LeaveMessageMVC/LMListForPublic.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.Windows.Forms; 12
13
using LeaveMessageMVC.MVC.BusinessLogicLayer.ParameterInformation; 14
using LeaveMessageMVC.MVC.DataBaseControlLayer; 15
using LeaveMessageMVC.MVC.BusinessLogicLayer; 16
using LeaveMessageMVC.MVC.BusinessLogicLayer.SomeFunctions; 17
18
//该源码下载自www.51aspx.com(51aspx.com) 19
//edit by 51aspx 20
public partial class LMListForPublic : System.Web.UI.Page 21
{ 22
LeaveMessageMVC.MVC.BusinessLogicLayer.ParameterInformation.LeaveMessagePara LMP = new LeaveMessagePara(); 23
int f=0; 24
const int cPageSize = 15; //设置分页控件每页显示的行数 25
26
protected void Page_Load(object sender, EventArgs e) 27
{ 28
if(Application["TableCount"]!=null) 29
30
f = (int)Application["TableCount"]; 31
32
if (!Page.IsPostBack) 33
{ 34
//禁止浏览器的缓存,防止用户发布信息后点“后退”返回到原来未发布的状态(虽然实际数据已写入DB) 35
Response.Cache.SetNoStore(); 36
Response.Cache.SetNoServerCaching(); 37
38
Response.Write("<script type=\"text/javascript\">"); 39
Response.Write("function CtrlEnter(button){"); 40
Response.Write("if(event.ctrlKey && event.keyCode==13)document.all[button].click();}"); 41
//Response.Write("var floor=" + Application["TableCount"] + ";"); 42
//Response.Write("function NextFloor(){floor--;}"); 43
Response.Write("</script>"); 44
TBcontents.Attributes.Add("onkeydown", "CtrlEnter('Submit');"); 45
46
if (Session["BUser"] != null) 47
{ 48
TBuser.Text = Session["BUser"].ToString(); 49
//Session["BUser"] = null; 50
} 51
if (Session["QQorMSN"] != null) 52
{ 53
TBQQMSN.Text = Session["QQorMSN"].ToString(); 54
//Session["QQorMSN"] = null; 55
} 56
57
if (Session["PageNumber"] != null) 58
{ 59
LMBind((int)Session["PageNumber"]); 60
Session["PageNumber"] = null; 61
} 62
else 63
LMBind(0); 64
} 65
} 66
67
protected void Submit_Click(object sender, EventArgs e) 68
{ 69
if (TBuser.Text == "" || TBQQMSN.Text == "" || TBcontents.Text == "") 70
{ 71
Response.Write("<Script Language=JavaScript>alert(\"提示:用户名、QQ/MSN、留言信息3项必填。\")</Script>"); 72
Response.Write("<Script Language=JavaScript>this.location.href=\"#IwantToSay\"</script>"); 73
74
Response.Write("<script>setTimeout(\"document.all.TBuser.focus();\",500);</script>"); 75
//上行代码也可写成两段 76
//Response.Write("<script>setTimeout(\"Focus()\",1000);</script>"); 77
//Response.Write("<script>function Focus(){document.all.TBuser.focus();}</script>"); 78
79
//TBuser.Focus(); //用这个在调试时总是提示内存不可读 80
} 81
else 82
{ 83
LMP.ID = AutoCreateID.NewID(); 84
LMP.User = FormatString.FormatStr(TBuser.Text); 85
LMP.QQMSN = FormatString.FormatStr(TBQQMSN.Text); 86
LMP.Title = FormatString.FormatStr(TBtitle.Text); 87
LMP.Contents = FormatString.FormatStr(TBcontents.Text); 88
LMP.WriteBack = ""; 89
LMP.SubmitTime = DateTime.Now; 90
91
if (LMManage.AddNewLeaveMessage(LMP)) 92
{ 93
//每次向数据库写入一条留言成功,就使保存 表行数 的全局变量 +1 94
Application.Lock(); 95
Application["TableCount"] = (int)Application["TableCount"] + 1; 96
Application.UnLock(); 97
98
TBtitle.Text = ""; 99
TBcontents.Text = ""; 100
LMBind(0); 101
102
//采用网页重定向的方法,防止用户提交后刷新页面又提示再一次提交 103
//(同时注意保留用户已填写的用户名和联系方式) 104
Session["BUser"] = LMP.User; 105
Session["QQorMSN"] = LMP.QQMSN; 106
Response.Redirect("LMListForPublic.aspx"); 107
} 108
else Response.Redirect("ShowErrorMsg.aspx?name=" + LMP.User); 109
} 110
} 111
112
Bind 169
170
protected string TitleAndFloor(string title) 171
{ 172
//在标题前加上楼数 173
174
if (title == "") 175
title = "无标题"; 176
177
return "#" + ((f--) - ((Convert.ToInt32(PageNumber.Text) - 1) * cPageSize)) + " 主题:" + title; 178
} 179
180
protected void LMGridView_RowCommand(object sender, GridViewCommandEventArgs e) 181
{ 182
//注意:该按钮事件其实没有指明是哪些按钮,因为这需要用到 CommandName 属性, 183
// 但该属性已被另作他用,所以点击GridView内任何一个按钮、链接(例如分页链接)都将触发该函数 184
//if (TBuser.Text == "") 185
//{ 186
// Response.Write("<Script Language=JavaScript>alert(\"提示:回复他人留言,你必须在下面的留言框输入您的用户名。\");</script>"); 187
// Response.Write("<Script Language=JavaScript>this.location.href=\"#IwantToSay\"</script>"); 188
189
// Response.Write("<script>setTimeout(\"document.all.TBuser.focus();\",1000);</script>"); 190
// //上行代码也可写成两段 191
// //Response.Write("<script>setTimeout(\"Focus()\",1000);</script>"); 192
// //Response.Write("<script>function Focus(){document.all.TBuser.focus();}</script>"); 193
194
// //TBuser.Focus(); //用这个在调试时总是提示内存不可读 195
//} 196
197
... 212
} 213
protected void Next_Click(object sender, EventArgs e) 214
{ 215
PageNumber.Text = Convert.ToString((Convert.ToInt32(PageNumber.Text) + 1)); 216
217
//LMBind((Convert.ToInt32(PageNumber.Text) - 1)); 218
Session["PageNumber"] = (Convert.ToInt32(PageNumber.Text) - 1); 219
Response.Redirect("LMListForPublic.aspx"); //为解决刷新问题 220
} 221
protected void Prev_Click(object sender, EventArgs e) 222
{ 223
PageNumber.Text = Convert.ToString((Convert.ToInt32(PageNumber.Text) - 1)); 224
225
//LMBind((Convert.ToInt32(PageNumber.Text) - 1)); 226
Session["PageNumber"] = (Convert.ToInt32(PageNumber.Text) - 1); 227
Response.Redirect("LMListForPublic.aspx"); //为解决刷新问题 228
} 229
protected void Button1_Click(object sender, EventArgs e) 230
{ 231
if (TextBox1.Text == "51aspx") 232
Response.Redirect("AdminControlPage.aspx"); 233
TextBox1.Text = ""; 234
} 235
} 236



LeaveMessageMVC.MVC.BusinessLogicLayer.ParameterInformation.LeaveMessagePara LMP 

}