private void CreateComment(JournalComment comment) { string headerText = ""; StringBuilder builder = new StringBuilder(); if (String.IsNullOrEmpty(comment.website)) { headerText = String.Format("Posted By: <a href='#'>{0}</a>", comment.name); } else { if (comment.website.IndexOf("http://") >= 0) { headerText = String.Format("Posted By: <a href='{0}' target='_blank'>{1}</a>", comment.website, comment.name); } else { headerText = String.Format("Posted By: <a href='http://{0}' target='_blank'>{1}</a>", comment.website, comment.name); } } HtmlElement headerDiv = HtmlPage.Document.CreateElement("div"); HtmlElement commentDiv = HtmlPage.Document.CreateElement("div"); HtmlElement footerDiv = HtmlPage.Document.CreateElement("div"); headerDiv.CssClass = "comment_header"; commentDiv.CssClass = "comment_text"; footerDiv.CssClass = "comment_footer"; headerDiv.SetProperty("innerHTML", headerText); commentDiv.SetProperty("innerHTML", HttpUtility.HtmlDecode(comment.comment)); footerDiv.SetProperty("innerHTML", String.Format("Posted on {0}", comment.entry_date.ToShortDateString())); HtmlElement comment_area = HtmlPage.Document.GetElementById("comment_area"); comment_area.AppendChild(headerDiv); comment_area.AppendChild(commentDiv); comment_area.AppendChild(footerDiv); CommentArea.Width = Convert.ToInt32(HtmlPage.Document.GetElementById("comment_area").GetProperty("offsetWidth")); CommentArea.Height = Convert.ToInt32(HtmlPage.Document.GetElementById("comment_area").GetProperty("offsetHeight")); }
private void Submit_Click(object sender, RoutedEventArgs e) { JournalComment comment = new JournalComment(); comment.name = Name.Text; comment.website = Website.Text; comment.comment = HttpUtility.HtmlEncode(HtmlPage.Window.Invoke("getEditorContent", null) as string); comment.user_id = settings.user_id; comment.entry_date = DateTime.Now; journalContext.JournalComments.Add(comment); journalContext.SubmitChanges((CommentSubmitted) => { if (!CommentSubmitted.HasError) { LoadComments(); Name.Text = ""; Website.Text = ""; HtmlPage.Window.Invoke("setEditorContent", ""); } }, null); }