Results 1 to 5 of 5

Thread: Saving a multiline textbox into db with html formatting?

  1. #1

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464

    Saving a multiline textbox into db with html formatting?

    I am creating a user forum, much like these ones. I am having a little problem though.

    When you type in your reply or new post, the newlines get lost when saving the text to the db (SQL Server 2000, text field). I want to be able to insert <br> tags for the newlines, but don't know how to go about it. Any suggestions?

    Example of what I mean:
    The empty lines between the paragraphs in this post, they don't show up when I save them to the db in my forums.

  2. #2
    Hyperactive Member Hampster's Avatar
    Join Date
    Feb 2001
    Location
    On my hamster wheel.
    Posts
    374
    VB Code:
    1. Txt.Text = Replace(Txt.Text,vbCrLF,"<br>")

    Then input Txt.Text into your Database as normal

  3. #3

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    That is great, but I am doing this in C#. Would I be looking for the \r\n in that case? I will give it a try.

  4. #4

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Ok, this is very annoying. Here is the code I am using:
    string message = MessageText.Text; // That is a multiline textbox.
    message.Replace(Environment.NewLine, "<br>");

    It doesn't do anything. It is like when the text is being posted back to the server, all newlines are taken out. Anyone know what is going on?

  5. #5

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Boy, I feel silly. I wasn't assigning the result of the replace back to a string variable. It is working now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width