ASP.NET多行文本框,允许在UTF-8以上输入 [英] ASP.NET Multiline textbox allowing input above UTF-8

查看:117
本文介绍了ASP.NET多行文本框,允许在UTF-8以上输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的web.config中,

In my web.config I have

<globalization
  fileEncoding="utf-8"
  requestEncoding="utf-8"
  responseEncoding="utf-8"
  culture="en-US"
  uiCulture="de-DE"
/>

在我的页面指令中,我有

In my page directive I have

ResponseEncoding="utf-8"

但是由于某种原因,带有TextMode ="MultiLine"的ASP TextBox允许输入UTF-8以外的字符.当我将以下文本行粘贴到非MultiLine的ASP TextBox中时

Yet for some reason an ASP TextBox with the TextMode="MultiLine" allows inputs of characters outside of UTF-8. When I paste the following line of text into an ASP TextBox that is not MultiLine

"test"

非UTF-8字符将被替换,但当我使用MultiLine TextBox时不会被替换.

the non UTF-8 characters are replaced, but not when I use a MultiLine TextBox.

有什么想法吗?

为了进一步解释设置,我在其中看到了这个问题,这里有4个文本区域可以放在ASP页上.

To explain a little more the set up I am seeing this problem in, here are 4 text areas that can be put on an ASP page.

<asp:TextBox ID="txtTest1" runat="server"></asp:TextBox>
<asp:TextBox ID="txtTest2" runat="server" TextMode="MultiLine"></asp:TextBox>
<input id="Text1" runat="server" />
<textarea id="Textarea1" cols="100" rows="8" runat="server"></textarea>

如果您使用page指令创建一个带有ResponseEncoding的页面,则使用上述带有全球化选项卡的web.config,并将带有引号的测试行复制并粘贴到这4种不同类型的文本区域中的每一个中,为什么?字体会有所不同吗?

If you make a page with the ResponseEncoding in your page directive, your web.config with the globalization tab described above, and copy and paste the test line, with quotes, into each of these 4 different types of text areas, why does the font come up different?

推荐答案

只需添加一些说明即可... UTF-8是涵盖所有Unicode字符的字符编码方案.因此,没有非UTF-8字符"之类的东西.

Just to add some clarification... UTF-8 is a character encoding scheme that covers all Unicode characters. Therefore there isn't any such thing as a "non UTF-8 character."

字符串的编码与屏幕上这些字符的图形表示无关(例如,在网页的< input type ="text">或< textarea>//textarea>控件中) .在您的示例中,某些字体将印刷者的引号显示为直引号,而另一些字体将完全相同的UTF-8字符显示为弯引号.

The encoding of a string has nothing to do with the graphical representation of those characters on the screen (e.g. in a web page's <input type="text"> or <textarea></textarea> controls). In your example, some fonts display the typographer's quotes as straight quotes while others display the very same UTF-8 character as curly quotes.

ResponseEncoding设置确定要传输哪些字节来表示构成页面HTML的字符,以及编码为表单帖子和返回到页面的URL的字符.常见编码为UTF-8,ISO 8859-1和Windows-1252.这些编码有很多相似之处,但也有差异.但是,您可以使用Windows-1252字符集和编码(其中也包括那些弯引号)来提供完全相同的页面,并且会看到完全相同的结果.

The ResponseEncoding setting determines what bytes are transmitted to represent the characters that make up the HTML of your page and the characters encoded in form posts and URLs back to your page. Common encodings are UTF-8, ISO 8859-1 and windows-1252. These encodings have a lot of similarities, but they also have their differences. However, you can deliver the very same page using the windows-1252 character set and encoding (which also includes those curly quote characters) and you'd see exactly the same result.

因此,简而言之,不要将字符编码与字体样式混淆.

So in a nutshell, don't confuse character encoding with font styles.

顺便说一句,由于在web.config中设置了相同的内容,因此您的ResponseEncoding ="utf-8"指令是多余的.而且无论如何,UTF-8是默认设置,因此您甚至不需要在web.config中使用它.

By the way, your ResponseEncoding="utf-8" directive is redundant since the same thing is set in web.config. And UTF-8 is the default anyway, so you may not even need it in your web.config.

这篇关于ASP.NET多行文本框,允许在UTF-8以上输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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