Word wrapping on Comments?

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

Sort Posts:

  • Re: Word wrapping on Comments?

    03-17-2006, 11:41 AM
    • Participant
      868 point Participant
    • BillKrat
    • Member since 08-19-2003, 7:30 PM
    • Amarillo, tx
    • Posts 176

    [Dy] Also note that I am a fledgling programmer, so I may be missing somthing that is VERY obvious to you :).

    Not so obvious so your doing good :)   Since we're using a <div> versus a literal we have to change the ltlComment type to an HtmlGenericControl type (reference code below).   I provided a formatting class so that the resulting output more closely resembles what the user typed in.  It also includes additional formatting commands to save typing.

    \Issues\UserControls\Comments.ascx.cs

    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");

             HtmlGenericControl ltlComment = (HtmlGenericControl) e.Item.FindControl("ltlComment");
             ltlComment.InnerHtml =
    clsFormatter.mFormattedContent(currentComment.Comment,true
    );
       
    }
    }

    public class clsFormatter{
       
    public static string mFormattedContent(string tsTextToFormat, bool blnWordWrap) {
             return mFormattedContent(tsTextToFormat);
       }
       public static string mFormattedContent(string tsTextToFormat) {
             
    string lsComment = tsTextToFormat;
             lsComment =
    HttpContext.Current.Server.HtmlEncode(lsComment);
             lsComment = lsComment.Replace(
    " ", "&nbsp;&nbsp;");
             lsComment = lsComment.Replace(
    "\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
             lsComment = lsComment.Replace("\r", "<BR>");
             lsComment = lsComment.Replace(
    "&gt;&gt;", ">");
             lsComment = lsComment.Replace(
    "&lt;&lt;", "<");
             lsComment = lsComment.Replace(
    "[!", "<font color=red><b>");
             lsComment = lsComment.Replace(
    "!]", "</font></b>");
             lsComment = lsComment.Replace(
    "[[", "<font color=blue><b>");
             lsComment = lsComment.Replace(
    "]]", "</font></b>");
             return lsComment;
    }

     

  • Re: Word wrapping on Comments?

    03-17-2006, 2:18 PM
    • Member
      109 point Member
    • Dycacian
    • Member since 02-27-2006, 6:51 PM
    • Posts 23
    Well it ate my code up, but it is just the original HTML without the PRE tags.
    -Dycacian
  • Re: Word wrapping on Comments?

    03-17-2006, 3:51 PM
    • Participant
      868 point Participant
    • BillKrat
    • Member since 08-19-2003, 7:30 PM
    • Amarillo, tx
    • Posts 176

    Dycacian wrote:
    Well it ate my code up, but it is just the original HTML without the PRE tags.

    Is that a good thing or a bad thing?   Let me know if we don't have you where you need to be and we'll get you there :)

  • Re: Word wrapping on Comments?

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

    I was talking about this forum..  I posted some code,  and it messed it all up  hehe. 

     

    I haven't tried your second idea yet. . I am just about to check it out . :D

     

    thanks,

    Dy

    -Dycacian
  • Re: Word wrapping on Comments?

    03-17-2006, 4:05 PM
    • Member
      109 point Member
    • Dycacian
    • Member since 02-27-2006, 6:51 PM
    • Posts 23

    one problem I see is that You are writing in C# and I am in VB,  but I still might be able to use the logic, and build somthing that does the same thing, though it will take some time.  I just have to figure it out. 

    -Dy

    -Dycacian
  • Re: Word wrapping on Comments?

    03-17-2006, 4:54 PM
    • Participant
      868 point Participant
    • BillKrat
    • Member since 08-19-2003, 7:30 PM
    • Amarillo, tx
    • Posts 176

    The following site has an online converter - tried to run it but I wouldn't be able to tell you if it did a good job or not (you would ;).

    I ran one method at a time (online).  Hope this helps!

    http://csharpconverter.claritycon.com/Default.aspx

  • Re: Word wrapping on Comments?

    05-26-2006, 5:28 AM
    • Member
      5 point Member
    • juniordude
    • Member since 05-26-2006, 8:37 AM
    • Posts 1

    This fix worked for me.  Thanks mcsenow  Smile [:)]

    juniordude

  • Re: Word wrapping on Comments?

    11-27-2006, 6:12 PM
    • Member
      5 point Member
    • dylandu
    • Member since 11-27-2006, 11:06 PM
    • Posts 1
    BillKrat:

    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>

     Just addtion, it will be perfect with attribute "word-break:break-all" being added. 

    So the statement should like this:

    <

    div style="width:780;word-wrap:break-word;word-break:break-all;left:0" id="ltlComment" Runat="Server" ></div>
  • Re: Word wrapping on Comments?

    07-29-2008, 10:16 AM
    • Participant
      802 point Participant
    • funluckykitty
    • Member since 04-11-2008, 1:46 PM
    • Indianapolis, Indiana
    • Posts 1,047

    I'm sending a confirmation email that includes text entered in a text box, but am losing all hard returns when the email is sent.  How do I keep the hard returns, or add a <BR>?

    --Susan
  • Re: Word wrapping on Comments?

    07-29-2008, 2:24 PM
    • Participant
      868 point Participant
    • BillKrat
    • Member since 08-19-2003, 7:30 PM
    • Amarillo, tx
    • Posts 176

    Hi Susan,

    I run my email body through a formatter, e.g.,   string myEmailBody = Formatter.FormattedContent(e.BodyText);

    The code for it follows; you'll see that I added some additional formatting commands.

    /// <summary>
    /// Summary description for Formatter
    /// </summary>
    public class Formatter{

        public static string FormattedContent(string textToFormat, bool isWordWrap) {
            return FormattedContent(textToFormat);
        }

        public static string FormattedContent(string textToFormat) {

            string comment = textToFormat;

            comment = HttpContext.Current.Server.HtmlEncode(comment);
            comment = comment.Replace("  ", "&nbsp;&nbsp;");
            comment = comment.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
            comment = comment.Replace("----", "<HR>");
            comment = comment.Replace("\r", "<BR>");
            comment = comment.Replace("&gt;&gt;", ">");
            comment = comment.Replace("&lt;&lt;", "<");
            comment = comment.Replace("[!", "<font color=red><b>");
            comment = comment.Replace("[[", "<font color=blue><b>");
            comment = comment.Replace("]]", "</font></b>");
            return comment;
        }

        public static string CommandLegend() {
            string retVal =
                "Formatting commands follow:<br />" +
                "<table border=1>" +
                "    <tr><td bgcolor=Gainsboro><b>Syntax</b></td>" +
                "        <td bgcolor=Gainsboro><b>Would appear as</b></td></tr>" +
                "    <tr>" +
                "        <td>" +
                "            [!This is a test]]" +
                "        </td>" +
                "        <td>" +
                "            <strong><span style=\"color: red\">This is a test</span></strong></td>" +
                "    </tr>" +
                "    <tr>" +
                "        <td>" +
                "            &nbsp;[[This is a test]]" +
                "        </td>" +
                "        <td>" +
                "            <strong><span style=\"color: #3300ff\">This is a test</span></strong></td>" +
                "    </tr>" +
                "    <tr>" +
                "        <td>" +
                "            ----;</td>" +
                "        <td>" +
                "            Horizontal line</td>" +
                "    </tr>" +
                "    <tr>" +
                "        <td>" +
                "            &lt;&lt;font color=red&gt;&gt;Hi!&lt;&lt;/font&gt;&gt;</td>" +
                "        <td>" +
                "            <span style=\"color: red\">Hi!</span></td>" +
                "    </tr>" +
                "</table>" ;
            return retVal;
        }

        public Formatter()
        {

        }
    }

  • Re: Word wrapping on Comments?

    11-06-2008, 2:41 PM
    • Member
      8 point Member
    • boloyang
    • Member since 10-27-2008, 1:06 PM
    • Posts 11

    I tried this and it worked for me. What I basically did was commented out the <pre> tags in the htlm and added three <br/> right before the ending </pre> tags. Works fine and looks good to me. 

Page 2 of 2 (26 items) < Previous 1 2