protected void btn_reply_Click(object sender, EventArgs e) { if (TextBox1.Text.Equals("")) { HttpContext.Current.Response.Write("<script>alert('Your message can not be empty')</script>"); } else { if (Session["loginData"] != null) { user = (User)Session["loginData"]; Forum f = new Forum(); f.CategoryID = catID; f.PostID = postID; f.Text = TextBox1.Text; f.UserID = user.Id; f.Date = DateTime.Now; DBconnection.addForumMessage(f); Response.Redirect(Request.RawUrl); } else { HttpContext.Current.Response.Write("<script>alert('You must be logged in, in order to post messages on forum.')</script>"); } } }
protected void btn_add_Click(object sender, EventArgs e) { //create a new Forum objet, then pass it as a parameter in order to add post title to the database Forum post = new Forum(catID, TextBox1.Text, DateTime.Now, user.Id); DBconnection.addForumNewPost(post); post.Text = TextBox2.Text; post.PostID = DBconnection.lastPK("ID", "ForumPosts"); //add the message assosiated with this post DBconnection.addForumMessage(post); HttpContext.Current.Response.Write("<script>alert('Your post has been added')</script>"); //redirect the user to his message Response.Redirect("ForumMessages.aspx?catID=" + post.CategoryID + "&postID=" + post.PostID); }