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

那年仲夏 提交于 2019-11-27 09:15:43

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

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

white-space: pre-wrap;

this also works:

lbl_PostContent.Text = lbl_PostContent.Text.Replace(vbCrLf, "<br />")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!