protected void btnMessage_Click(object sender, EventArgs e) { int id = Convert.ToInt32(ViewState["VideoID"]); if (Session["UserName"] != null) { if (Page.IsValid) { int userid = Convert.ToInt32(Session["UserID"]); int videoid = Convert.ToInt32(Request.QueryString["VideoID"]); Leavewords leavewords = new Leavewords(); leavewords.UserID = userid; leavewords.VideoID = videoid; leavewords.LeaveContent = txtMessage.Text.Trim(); leavewords.LeaveTime = DateTime.Now; int result = LeavewordsService.InsertLeavewords(leavewords); if (result >= 1) { ScriptManager.RegisterClientScriptBlock(MessageUpdatePanel, this.GetType(), "click", "alert('留言成功')", true); BindMessage(); txtMessage.Text = ""; } else { ScriptManager.RegisterClientScriptBlock(MessageUpdatePanel, this.GetType(), "click", "alert('留言失败')", true); } } } else { ScriptManager.RegisterClientScriptBlock(MessageUpdatePanel, this.GetType(), "click", "alert('您必须先登录才能发表评论');", true); ScriptManager.RegisterStartupScript(MessageUpdatePanel, MessageUpdatePanel.GetType(), "updateScript", "window.location.href='Login.aspx'", true); } }
//发表评论 protected void pinglun_Click(object sender, EventArgs e) { if (Session["User_ID"] != null) { try { int id = Convert.ToInt32(Request.QueryString["id"].ToString()); Leavewords leavewords = new Leavewords(); leavewords.News_ID = id; leavewords.User_ID = int.Parse(Session["User_ID"].ToString()); leavewords.Leavewords_Time = DateTime.Now; leavewords.Leavewords_Content = txtContent.Text; if (LeavewordsService.InsertLeavewords(leavewords) == 1) { txtContent.Text = ""; ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('评论成功!');", true); BindBC(); } else { ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('评论失败!');", true); } } catch (Exception ex) { Response.Write("错误原因:" + ex.Message); } } else { ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "updateScript", "alert('对不起,请先登录!');", true); } }