您目前尚未登陆,请选择【登陆】或【注册
首页->留言本类->51aspx修正版简单三层留言板源码>>index.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:51aspx修正版简单三层留言板源码
当前文件:文件类型 LeaveMessageMVC/index.aspx.cs打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.WebControls; 9using System.Web.UI.WebControls.WebParts; 10using System.Web.UI.HtmlControls; 11using System.Windows.Forms; 12 13using LeaveMessageMVC.MVC.BusinessLogicLayer.ParameterInformation; 14using LeaveMessageMVC.MVC.DataBaseControlLayer; 15using LeaveMessageMVC.MVC.BusinessLogicLayer; 16using LeaveMessageMVC.MVC.BusinessLogicLayer.SomeFunctions; 17 18public partial class LeaveMessagePage : System.Web.UI.Page 19{ 20 LeaveMessageMVC.MVC.BusinessLogicLayer.ParameterInformation.LeaveMessagePara LMP = new LeaveMessagePara(); 21 22 protected void Page_Load(object sender, EventArgs e) 23 { 24 //禁止浏览器的缓存,防止用户发布信息后点“后退”返回到原来未发布的状态(虽然实际数据已写入DB) 25 Response.Cache.SetNoStore(); 26 Response.Cache.SetNoServerCaching(); 27 28 Response.Write("<script type=\"text/javascript\">"); 29 Response.Write("function CtrlEnter(button){"); 30 Response.Write("if(event.ctrlKey && event.keyCode==13)document.all[button].click();}"); 31 Response.Write("var floor=" + Application["TableCount"] + ";"); 32 Response.Write("function NextFloor(){floor--;}"); 33 Response.Write("</script>"); 34 35 if (!Page.IsPostBack) 36 { 37 LMBind(); 38 TBcontents.Attributes.Add("onkeydown", "CtrlEnter('Submit');"); 39 40 if (Session["BUser"] != null) 41 { 42 TBuser.Text = Session["BUser"].ToString(); 43 //Session["BUser"] = null; 44 } 45 if (Session["QQorMSN"] != null) 46 { 47 TBQQMSN.Text = Session["QQorMSN"].ToString(); 48 //Session["QQorMSN"] = null; 49 } 50 } 51 } 52 53 protected void Submit_Click(object sender, EventArgs e) 54 { 55 if (TBuser.Text == "" || TBQQMSN.Text == "" || TBcontents.Text == "") 56 { 57 Response.Write("<Script Language=JavaScript>alert(\"提示:用户名、QQ/MSN、留言信息3项必填。\")</Script>"); 58 Response.Write("<Script Language=JavaScript>this.location.href=\"#IwantToSay\"</script>"); 59 60 Response.Write("<script>setTimeout(\"document.all.TBuser.focus();\",500);</script>"); 61 //上行代码也可写成两段 62 //Response.Write("<script>setTimeout(\"Focus()\",1000);</script>"); 63 //Response.Write("<script>function Focus(){document.all.TBuser.focus();}</script>"); 64 65 //TBuser.Focus(); //用这个在调试时总是提示内存不可读 66 } 67 else 68 { 69 LMP.ID = AutoCreateID.NewID(); 70 LMP.User = FormatString.FormatStr(TBuser.Text); 71 LMP.QQMSN = FormatString.FormatStr(TBQQMSN.Text); 72 LMP.Title = FormatString.FormatStr(TBtitle.Text); 73 LMP.Contents = FormatString.FormatStr(TBcontents.Text); 74 LMP.WriteBack = ""; 75 LMP.SubmitTime = DateTime.Now; 76 77 if (LMManage.AddNewLeaveMessage(LMP)) 78 { 79 //每次向数据库写入一条留言成功,就使保存 表行数 的全局变量 +1 80 Application.Lock(); 81 Application["TableCount"] = (int)Application["TableCount"] + 1; 82 Application.UnLock(); 83 84 TBtitle.Text = ""; 85 TBcontents.Text = ""; 86 LMBind(); 87 88 //采用网页重定向的方法,防止用户提交后刷新页面又提示再一次提交 89 //(同时注意保留用户已填写的用户名和联系方式) 90 Session["BUser"] = LMP.User; 91 Session["QQorMSN"] = LMP.QQMSN; 92 Response.Redirect("index.aspx"); //为解决刷新问题 93 } 94 else Response.Redirect("ShowErrorMsg.aspx?name=" + LMP.User); 95 } 96 } 97 98 protected void LMBind() 99 { 100 if(!DBControl.AccessConnection) 101 LeaveMessageList.DataSource = LMManage.GetLeaveMessage(10); 102 else 103 LeaveMessageList.DataSource = LMManage.aGetLeaveMessage(10); 104 LeaveMessageList.DataBind(); 105 } 106 107 protected string ShortString(string content, string id) 108 { 109 //限制显示“留言内容”的字符数,避免篇幅太大 110 if (content.Length > 180) 111 return content.Substring(0, 150) + "...&nbsp;&nbsp;" + "<a href=\"ShowDetail.aspx?d_ID=" + id + "\">阅读全文</a>"; 112 else 113 return content; 114 115 } 116 117 protected void LeaveMessageList_ItemCommand(object sender, DataListCommandEventArgs e) 118 { 119 //if (TBuser.Text == "") 120 //{ 121 // Response.Write("<Script Language=JavaScript>alert(\"提示:回复他人留言,你必须在下面的留言框输入您的用户名。\");</script>"); 122 // Response.Write("<Script Language=JavaScript>this.location.href=\"#IwantToSay\"</script>"); 123 124 // Response.Write("<script>setTimeout(\"document.all.TBuser.focus();\",1000);</script>"); 125 // //上行代码也可写成两段 126 // //Response.Write("<script>setTimeout(\"Focus()\",1000);</script>"); 127 // //Response.Write("<script>function Focus(){document.all.TBuser.focus();}</script>"); 128 129 // //TBuser.Focus(); //用这个在调试时总是提示内存不可读 130 //} 131 132 ... 147 } 148} 149
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:51aspx修正版简单三层留言板源码
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号