ASP.Net Text with LineBreak from Multi-Line-TextBox to save in a database

前端 未结 3 1541
别那么骄傲
别那么骄傲 2020-12-01 21:24

I have PrivateMessage-System in my new Community-Page.

I have a Multiline-Textbox for the Text of a private message. I save this text in a string, this string in a n

相关标签:
3条回答
  • 2020-12-01 22:01

    You can solve this with CSS. Assign this CSS to your label:

    white-space: pre-wrap;

    0 讨论(0)
  • 2020-12-01 22:07

    First of all is it actually saving the line breaks to your table? If so, what does it save them as, eg \r\n or CRLF or what?

    Your label outputs html, so the only thing that will create a break is a <br /> tag. So you need to find and replace whatever is saved in the database:

    Label1.Text = someDatabaseText.Replace("\r\n", "<br />");
    

    Or even better, do the .Replace() before you save it to the database:

    someDatabaseField = TextBox1.Text.Replace("\r\n", "<br />");
    
    0 讨论(0)
  • 2020-12-01 22:14

    this also works:

    lbl_PostContent.Text = lbl_PostContent.Text.Replace(vbCrLf, "<br />")
    
    0 讨论(0)
提交回复
热议问题