Word wrapping on Comments?

Last post 11-06-2008 2:41 PM by boloyang. 25 replies.

Sort Posts:

  • Word wrapping on Comments?

    04-04-2004, 3:45 AM
    • Member
      35 point Member
    • ethanwa
    • Member since 04-02-2004, 1:26 AM
    • Seattle, WA
    • Posts 7
    Here's the code. Now how do I make the comment text word-warp? Do I need to change the CSS code instead?

    Ethan


    <asp:datagrid id="grdComments" Runat="Server" CellPadding="2" BorderStyle="None" BorderColor="White"
    Width="600" PageSize="5" AllowPaging="true" AutoGenerateColumns="false">
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:Label id="lblCreatorDisplayName" Runat="Server" />
    commented on
    <asp:Label id="lblDateCreated" Runat="Server" />
    <hr />
    <pre>
    <asp:Literal id="ltlComment" Runat="Server" />
    </pre>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    <pagerstyle horizontalalign="Center"></pagerstyle>
    </asp:datagrid>
    Ethan C Allen

    QA Tester - C#, VB.NET
  • Re: Word wrapping on Comments?

    04-07-2004, 5:29 PM
    • Participant
      873 point Participant
    • swalther
    • Member since 08-04-2002, 10:55 AM
    • Seattle, WA
    • Posts 173
    • AspNetTeam
    Hi ethanwa,


    Thanks for using the Issue Tracker!

    If you take out the <pre> tags, then the comments will wordwrap.

    I added the <pre> 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
  • Re: Word wrapping on Comments?

    06-10-2004, 5:39 PM
    • Member
      5 point Member
    • hotscooter250
    • Member since 04-09-2003, 4:03 PM
    • Posts 1
    How can I change the width of the screen? It is too wide at 1024 X 768. Removing the <pre> tags does allow the text to wrap. It would be great to be able to increase font size too!

    Thanks!

    Tracy
  • Re: Word wrapping on Comments?

    06-14-2004, 12:16 PM
    • Member
      175 point Member
    • JesseA
    • Member since 07-10-2002, 7:08 PM
    • Posts 35
    There is more to it than just removing the <pre> tags. If you do remove the <pre> 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.
  • Re: Word wrapping on Comments?

    06-21-2004, 5:35 PM
    • Member
      10 point Member
    • JEstes
    • Member since 06-21-2004, 5:14 PM
    • Posts 2
    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 <br> tag. This will allow the user to enter any HTML they wish as a comment, including <br>, 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, "<!br!>"), 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 <br> 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("&lt;!br!&gt;", "<br>");
    }
    }





    Edited by SomeNewKid. Please post code between <code> and </code> tags.



  • Re: Word wrapping on Comments?

    06-30-2004, 1:56 PM
    • Member
      25 point Member
    • SCalhoun
    • Member since 06-23-2004, 11:17 AM
    • Posts 5
    where exactly are these files located that we need to change?
  • Re: Word wrapping on Comments?

    06-30-2004, 2:13 PM
    • Member
      25 point Member
    • SCalhoun
    • Member since 06-23-2004, 11:17 AM
    • Posts 5
    I removed the <pre> tags and then got an error. the error is:

    Object reference not set to an instance of an object.

    any ideas?
  • Re: Word wrapping on Comments?

    07-04-2004, 4:42 PM
    • Participant
      873 point Participant
    • swalther
    • Member since 08-04-2002, 10:55 AM
    • Seattle, WA
    • Posts 173
    • AspNetTeam
    Hi SCalhoun,

    You need to modify the Issues\UserControls\Comments.ascx file. You should be able to simply remove the opening and closing <pre> tags. Since this is just HTML, you should not need to recompile the application for the modifications to take effect.

    Hope this helps!

    Stephen Walther
  • Re: Word wrapping on Comments?

    03-17-2005, 3:21 PM
    • Member
      208 point Member
    • Schelloeh
    • Member since 07-22-2004, 8:38 AM
    • Posts 59
    Hi,

    I just wanted to use this - but in VB. The
    ltlComment.Text.Replace("&lt;!br!&gt;", "<br>") 
    does not show line breaks. I tried with ("&lt;br&gt;", "<br>") and ("&lt; br &gt;", "<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
  • Re: Word wrapping on Comments?

    03-23-2005, 12:25 AM
    • Participant
      1,084 point Participant
    • mcsenow
    • Member since 05-24-2003, 7:29 PM
    • McLean, VA
    • Posts 218
    For the VB version, to allow word wrap and paragraph format:

    1. Remove the PRE tag

    2. In the file <IssueTracker Folder>\Issues\UserControls\Comments.ascx.vb, change:

    ltlComment.Text = Server.HtmlEncode(currentComment.Comment)

    to

    ltlComment.Text = Replace(currentComment.Comment, System.Environment.NewLine, "<br>")
  • Re: Word wrapping on Comments?

    04-04-2005, 6:03 AM
    • Member
      208 point Member
    • Schelloeh
    • Member since 07-22-2004, 8:38 AM
    • Posts 59
    Thanks, that works! The word wrapping and the line breaks.Smile [:)]
  • Re: Word wrapping on Comments?

    04-17-2005, 1:02 AM
    • Participant
      868 point Participant
    • BillKrat
    • Member since 08-19-2003, 7:30 PM
    • Amarillo, tx
    • Posts 176

    Below is an excerpt from my requirements log (Issue Tracking).   I required the <PRE></PRE> tags so I went the route of the WrapText() method.   If your interested in the code I provide a link below it.  The area in blue is the original code.

    // WK.2005.04.16 RQ32
    // Moved txtComment.Text.Trim() from following line to WrapText parameter
    // Wrapped wordwrap in error handler and defined comment so it is in scope
    IssueComment comment;
    try {
          string lsComment = GWN.String.clsStuff.WrapText(txtComment.Text.Trim(),110);
          comment = new IssueComment(IssueId, lsComment, Page.User.Identity.Name);
    } catch (Exception loError){
          // Wordwrap is in test - if we have an unforeseen error we don't want
          // to lose the comment.  We can use the comment line to troubleshoot
          // the error.
          comment = new IssueComment(IssueId, txtComment.Text.Trim(), Page.User.Identity.Name);
    }

    https://www.amarillo.tv/Programming/Issues/IssueDetail.aspx?id=32 

           Login: Forum
    Password: asp.net

    Note: It is attached as clsStuff (evolved to wordwrap - have to rename it one day;).  It calls two methods from the Foxpro Toolkit; a public domain library created for Foxpro developers - it is chock full of very useful methods.  The cool things is they provide source code for all methods in VB and C#.    I have the VFPToolkitNET.ZIP available on the attachment tab also.

     

  • Re: Word wrapping on Comments?

    03-16-2006, 2:07 PM
    • Member
      109 point Member
    • Dycacian
    • Member since 02-27-2006, 6:51 PM
    • Posts 23

    BillKrat,

    Have you seen anything like the code you wrote in VB?  I am having to do all of this in VB, so I am forced for now to just remove the PRE tags, but I want to get back the ability to show code samples.  If you or anyone else hasany ideas, please let me know. 

    Thanks,

    Dy

    -Dycacian
  • Re: Word wrapping on Comments?

    03-16-2006, 10:57 PM
    • Participant
      868 point Participant
    • BillKrat
    • Member since 08-19-2003, 7:30 PM
    • Amarillo, tx
    • Posts 176

    Hi Dy,

    Didn't get a notification on this one - sorry about the delay (I was browsing around and stumbled in).

    In the migration to .NET 2.0 I scraped a lot of my old stuff (to start over) to include the code I used to do the wordwrap so I had to figure it out again EXCEPT! I found an easy HTML method on the Microsoft site :)   Its the magical line in red!

    \Issues\UserControls\comments.ascx

    <asp:TemplateColumn>
       
    <ItemTemplate
    >
       
    <table border
    ="1">
          
    <tr
    >
            
       <td bgcolor="#000099"
    >
                      
    <font color=yellow><b
    >
                     
    <asp:Label id="lblCreatorDisplayName" Runat="Server" Font-Italic="True" /></font
    >
                      <font color=white><b>&nbsp;<em>commented on </em
    >
                         <asp:Label id="lblDateCreated" Runat="Server" Font-Italic="True" /><em>&nbsp;<br /></em
    >
                       </b></font
    >
                 </td
    >
         </tr
    >
          <tr
    >
                <td
    >
                        <div style="width:780;word-wrap:break-word;left:0" id="ltlComment" Runat="Server"
    />
                </
    td
    >
         </tr
    >
    </table
    >
    </ItemTemplate>

     

     

     

     

  • Re: Word wrapping on Comments?

    03-17-2006, 10:30 AM
    • Member
      109 point Member
    • Dycacian
    • Member since 02-27-2006, 6:51 PM
    • Posts 23

    Unless I did somthing wrong It didn't work.  it gave me an Invalid Cast error.

    My code looks like this.  My line is in red.  Notice the lack of <PRE> tags

      commented on <hr /> <font color=#ff0000><strong></strong></font>

    NOTE: I tried this a few different ways.  I did it with the original code behind in place, and With the modified code.  Both had the same result. 

    Original Code = ltlComment.Text = Server.HtmlEncode(currentComment.Comment)

    Modified Code = ltlComment.Text = Replace(currentComment.Comment, System.Environment.NewLine, "<br>")

    Also note that I am a fledgling programmer, so I may be missing somthing that is VERY obvious to you :).  But I am trying hehe.  At least I was able to modify it enough to get it into production.  I just want to beable to give as many features as possible.

    Thanks for all your help.  I guess in the end I could just use the <xmp> tags, but I would rather not have to train all my users to remember that.

    THanks,

    Dy

    -Dycacian
Page 1 of 2 (26 items) 1 2 Next >