Hi ethanwa, Thanks for using the Issue Tracker! If you take out the
tags, then the comments will wordwrap.
I added the
tags in case you needed to post code samples in the comments. Typically, you want code snippets to preserve whitespace.
Hope this helps!
Stephen Walther
tags you will no longer retain ANY whitesapce, carriage returns, etc... I swapped out the Literal comment control in the datagrid for a ReadOnly Textbox with the same attributes as the one used for the Add Comment. This works, but won't print, and looks klunky with a lot of short comments. I'm think going to build a custom control in lieu of finding a control that will wrap and render whitespace and escapes properly.
I came up with a way to retain white space and still allow html to be displayed instead of being rendered as html formatting in the comments section. My C# is more than a bit rusty so bare with me on this one. The idea is to convert the line breaks the user
entered into some character sequence the user is not likely to enter as a comment. Then after the HtmlEncode method has been called, we will convert this special character sequence into an HTML
tag. This will allow the user to enter any HTML they wish as a comment, including
, and it will be displayed as text and not rendered by the browser. The code looks something like this:
//First we have to change the AddComment function so it saves our special character sequence instead of the line break the user entered.
void AddComment(Object s, EventArgs e)
{
if (Page.IsValid)
{
IssueComment comment = new IssueComment(IssueId, txtComment.Text.Trim().Replace(System.Environment.NewLine, ""), Page.User.Identity.Name);
comment.Save();
txtComment.Text = String.Empty;
BindComments();
}
}
//Now we have to change the display function so it will convert our special character sequence to the HTML
tag but we need to wait until after the HtmlEncode method has been called.
void grdCommentsItemDataBound(Object s, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
IssueComment currentComment = (IssueComment)e.Item.DataItem;
Label lblCreatorDisplayName = (Label)e.Item.FindControl( "lblCreatorDisplayName" );
lblCreatorDisplayName.Text = currentComment.CreatorDisplayName;
Label lblDateCreated = (Label)e.Item.FindControl( "lblDateCreated" );
lblDateCreated.Text = currentComment.DateCreated.ToString("f");
Literal ltlComment = (Literal)e.Item.FindControl( "ltlComment" );
ltlComment.Text = Server.HtmlEncode(currentComment.Comment);
ltlComment.Text = ltlComment.Text.Replace("<!br!>", "
");
}
}
Edited by SomeNewKid. Please post code between <code> and </code> tags.
does not show line breaks. I tried with ("<br>", "
") and ("< br >", "
") without any change. How can I find out, which string is used for the break? I cannot see it in the SQL server or in the page. If I remove the PRE in HTML, also the line breaks are omitted. So I need a combination of both. Thanks, BS
For the VB version, to allow word wrap and paragraph format: 1. Remove the PRE tag 2. In the file \Issues\UserControls\Comments.ascx.vb, change: ltlComment.Text = Server.HtmlEncode(currentComment.Comment) to ltlComment.Text = Replace(currentComment.Comment,
System.Environment.NewLine, "
")
ethanwa
Member
35 Points
7 Posts
Word wrapping on Comments?
Apr 04, 2004 07:45 AM|LINK
QA Tester - C#, VB.NET
swalther
Participant
887 Points
180 Posts
Microsoft
Re: Word wrapping on Comments?
Apr 07, 2004 09:29 PM|LINK
hotscooter25...
Member
5 Points
1 Post
Re: Word wrapping on Comments?
Jun 10, 2004 09:39 PM|LINK
JesseA
Member
175 Points
35 Posts
Re: Word wrapping on Comments?
Jun 14, 2004 04:16 PM|LINK
JEstes
Member
10 Points
2 Posts
Re: Word wrapping on Comments?
Jun 21, 2004 09:35 PM|LINK
tag. This will allow the user to enter any HTML they wish as a comment, including
, and it will be displayed as text and not rendered by the browser. The code looks something like this:
//First we have to change the AddComment function so it saves our special character sequence instead of the line break the user entered. void AddComment(Object s, EventArgs e) { if (Page.IsValid) { IssueComment comment = new IssueComment(IssueId, txtComment.Text.Trim().Replace(System.Environment.NewLine, ""), Page.User.Identity.Name); comment.Save(); txtComment.Text = String.Empty; BindComments(); } } //Now we have to change the display function so it will convert our special character sequence to the HTML tag but we need to wait until after the HtmlEncode method has been called. void grdCommentsItemDataBound(Object s, DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { IssueComment currentComment = (IssueComment)e.Item.DataItem; Label lblCreatorDisplayName = (Label)e.Item.FindControl( "lblCreatorDisplayName" ); lblCreatorDisplayName.Text = currentComment.CreatorDisplayName; Label lblDateCreated = (Label)e.Item.FindControl( "lblDateCreated" ); lblDateCreated.Text = currentComment.DateCreated.ToString("f"); Literal ltlComment = (Literal)e.Item.FindControl( "ltlComment" ); ltlComment.Text = Server.HtmlEncode(currentComment.Comment); ltlComment.Text = ltlComment.Text.Replace("<!br!>", " "); } }Edited by SomeNewKid. Please post code between <code> and </code> tags.
SCalhoun
Member
25 Points
5 Posts
Re: Word wrapping on Comments?
Jun 30, 2004 05:56 PM|LINK
SCalhoun
Member
25 Points
5 Posts
Re: Word wrapping on Comments?
Jun 30, 2004 06:13 PM|LINK
swalther
Participant
887 Points
180 Posts
Microsoft
Re: Word wrapping on Comments?
Jul 04, 2004 08:42 PM|LINK
Schelloeh
Member
208 Points
64 Posts
Re: Word wrapping on Comments?
Mar 17, 2005 07:21 PM|LINK
ltlComment.Text.Replace("<!br!>", " ")does not show line breaks. I tried with ("<br>", "") and ("< br >", "
") without any change. How can I find out, which string is used for the break? I cannot see it in the SQL server or in the page. If I remove the PRE in HTML, also the line breaks are omitted. So I need a combination of both. Thanks, BS
mcsenow
Participant
1084 Points
218 Posts
Re: Word wrapping on Comments?
Mar 23, 2005 04:25 AM|LINK
")
DotNetNuke Modules Issue Tracker, Timesheet, MSSQL Reporting Services, Visitor Counter