开发者

keep formatting entered in asp.net textbox (carriage return, new line, etc)

I have a textbox using multiline mode and when I create the stored procedure parameter for updating I use Server.HtmlEncode on the textbox value. I can copy the content from the data record into Notepad and it shows the spaces where the user has pressed the Enter key for new paragraphs.

When displaying that content on a page (not a textbox for editing; just assigning the content 开发者_开发技巧to a Literal control), it has all the text run together.

I have done some searches about using Replace and different escape sequences or Environment.NewLine. I am still confused about how to have the text display as the user entered it.


Assuming you're using C# you can do the following when you display the string on the page

theStringYouWantToFormat.Replace(char.ConvertFromUtf32(13),"<br/>")

When you call Server.HtmlEncode on the value you grab from a text box it'll look at the text and encode any HTML tags contained in that text box so for example <script></script> would be encoded to &lt;script&gt;&lt;/script&gt;.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜