0

I have an ASP page with this in the header:

<%@CodePage=65001 %>
<%  response.codepage=65001
    response.charset="utf-8" %>
<head>
<meta charset="utf-8">
</head>

I retrieve data from an MS SQL database table (that contains French characters with accents and so forth) via another ASP file, and insert that text into my page dynamically with Javascript, and everything looks perfect.

Note that if I take all of that header code out, it still displays correctly. But my other hard-coded characters on the page (such as “ ” ‘ ’ —, etc) do not display. So I leave the header code in.

I have another "add to cart" ASP file that retrieves the same data and inserts it into a cart table. I temporarily display the data in my script, in order to see what I am inserting, but the text is distorted. For example:

réexpédié

Instead of:

réexpédié

When I check the cart table, it is also distorted there.

If I insert this at the top of my "add to cart" ASP file:

<meta charset="utf-8">

...the display on the screen looks good, but the data stored in the cart table is still distorted. I'm not sure why it looks good on the screen, because in my main ASP file (where I insert the same text) it doesn't matter if I include the meta tag or not.

I am confused as to which parts of my code are causing the text to display correctly and which are causing it to fail.

Even looking at my ASP file that retrieves the data for Javascript to insert, if I load that URL in my browser, the text is incorrect. But when I insert it into the main ASP page, it is correct. If I add the meta tag to the first ASP file, now that is correct. But on the main page, it doesn't matter if I include the meta tag or not.

How can I resolve this so I get consistent text characters in all of these instances?

BB Design
  • 695
  • 12
  • 26
  • 2
    Classic ASP! I loved that tech 10 years longer than I should have, 10 years ago. Anyway I would check through your parameters and data types and literals and make sure they're always declared as `nvarchar`, the same collation is used in all tables, and string literals or concatenations always start with N (e.g. `N'text'`). Compare: `SELECT '', N'';` – Aaron Bertrand Sep 28 '21 at 15:32
  • 2
    Does this answer your question? [Convert UTF-8 String Classic ASP to SQL Database](https://stackoverflow.com/questions/21866225/convert-utf-8-string-classic-asp-to-sql-database) – user692942 Sep 28 '21 at 15:47
  • 1
    Check the physical asp files are saved as UTF-8 ([Step 1.](https://stackoverflow.com/a/21914278/692942)). Also, `` is completely irrelevant as `Response.Charset` is doing the same thing. – user692942 Sep 28 '21 at 15:48
  • My physical files are UTF-8. Here is what I find: if I retrieve from the database in my ASP script and display immediately, the characters are incorrect. If I retrieve from the database via Javascript AJAX, and insert the text dynamically into the page, the characters are correct. I don't understand why those two methods would have a different result. – BB Design Sep 28 '21 at 16:21
  • @BBDesign Are you using `NVARCHAR` fields to store the data? If not you will need to. – user692942 Sep 28 '21 at 16:43

1 Answers1

0

As a french programmer specialized in Classic ASP for years (yes, still), in addition to your header instructions, I think that Session.CodePage = 65001 may help you too.

What works for me on many websites/intranets/extranets to properly display accented international characters like french ones, both on the HTML page and in the Javascript parts of the webapp is this exact sequence at the top of every page, wether is is displaying data to the browser in HTML and/or JS, or just performing some backend tasks such as inserting in database. Use it on EVERY Classic ASP page :

<%@codepage=65001%>
<%
Session.CodePage = 65001
Response.CodePage = 65001
Response.CharSet = "utf-8"
%>

Then

<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

Please also note that if you change Session.CodePage from page to page, this will confuse characters displaying on the next loaded pages. Make sure your are consistent with this Session.CodePage property. If you mess things up, recycle the IIS Application Pool then start over your tests.

AlexLaforge
  • 499
  • 3
  • 19