views:

617

answers:

2

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"

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”

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

Any ideas why?

EDIT: 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>

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?

A: 

Hi Justin,
What you are seeing is the different default fonts that are applied to the text area (multiline textbox) verse textbox (input). Text areas use Courier New and single line textboxes use Arial. If you apply a style that sets the font-family to be the same for both the textbox and the textarea then your pasted text will match. Try these and you should see that the pasted contents all match exactly:

<asp:TextBox ID="txtTest1" runat="server" style="font-family: Courier New;"></asp:TextBox>
<asp:TextBox ID="txtTest2" runat="server" TextMode="MultiLine" style="font-family: Courier New;"></asp:TextBox>
<input id="Text1" runat="server" style="font-family: Courier New;" />
<textarea id="Textarea1" cols="100" rows="8" runat="server" style="font-family: Courier New;"></textarea>
Jeff Widmer
Interesting, I would have thought the settings at the web.config level and the Page Directive would pass those settings along to all controls when the ASP is turned into html. Thanks Jeff, I'll give this a shot.
Justin C
hmmmm... i don't think you can set font-family in the web.config or the Page Directive. You could set font-family in a global css style sheet if you want to. What settings are you thinking that you set in web.config that would change the font-family of the textbox?
Jeff Widmer
The tag at the very beginning. It's "globilization", it's a section of the web.config . I got that information from the following MSDN article: http://msdn.microsoft.com/en-us/library/39d1w2xf.aspx
Justin C
Globalization does not drive the font that is used. The font comes strictly from the styles that are set on the page (or the default style of the text boxes). Globalization would come into play when displaying dates or currency (what order is the month, day, year specified or is a comma or period used to separate dollars from cents, etc.). The font that is used to display the text in a text box is not from the globalization settings.
Jeff Widmer
+3  A: 

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

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.

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.

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.

Mike Schenk
Thanks Mike. I figured they were redundant, I just wanted to show that I had done everything I had found in my research. Great explanation.
Justin C