保持在 asp.net 文本框中输入的格式(回车、换行等) [英] keep formatting entered in asp.net textbox (carriage return, new line, etc)

查看:28
本文介绍了保持在 asp.net 文本框中输入的格式(回车、换行等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用多行模式的文本框,当我创建用于更新的存储过程参数时,我在文本框值上使用了 Server.HtmlEncode.我可以将数据记录中的内容复制到记事本中,它会显示用户为新段落按下 Enter 键的空格.

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.

当在页面上显示该内容时(不是用于编辑的文本框;只是将内容分配给 Literal 控件),它会将所有文本放在一起.

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.

我已经做了一些关于使用替换和不同转义序列或 Environment.NewLine 的搜索.我仍然对如何在用户输入时显示文本感到困惑.

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.

推荐答案

假设您使用的是 C#,您可以在页面上显示字符串时执行以下操作

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

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

当您对从文本框中获取的值调用 Server.HtmlEncode 时,它会查看文本并对包含在该文本框中的任何 HTML 标记进行编码,例如 <script></script> 将被编码为 &lt;script&gt;&lt;/script>.

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;.

这篇关于保持在 asp.net 文本框中输入的格式(回车、换行等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆