treehouse : what would you like to learn today?
Web Design Web Development iOS Development

How to preserve line breaks in a textarea

  • Hello,

    Does anyone know how to preserve line breaks in a text area? I'm having a problem in our custom CMS where when you type something in a text area in the back end, the line breaks don't show up on the front end. So it'll look like this in the back end:

    text area

    text area

    text area

    But will come out like this on the front end:

    text area text area text area.

    I know it's possible since this forum is obviously doing it, but I just have no clue how. Does anyone have an idea?

  • It's your custom CMS. How do you have your text fields set up?

    BTW, I had to edit your OP to get the original vertical 'text areas' to show properly so perhaps this forum isn't the best example.

  • Ah, I guess maybe it isn't. I just know it is set up using ASP.net. Our programmer only works on a limited basis so we've been trying to solve anything we can on our own. Maybe this is something that is beyond me that will need programming expertise. I was hoping there may be a simple solution.

    This is the code I pulled from the CMS that calls the text box

    <asp:TextBox ID="Keywords" runat="server" Width="448px" TextMode="MultiLine" TabIndex="14"></asp:TextBox>
    
  • Where you output the string, something like:

    myString.Replace("\r\n", "
    ");

  • damnit... in the seconds parameter: < br > < br>

  • Awesome. Hopefully this bit of code they provide works within the asp tags. Thanks!