Reputation: 5264
I'm having a problem with Spanish characters in a classic asp site. A user is able to submit their name/address in a form on an aspx page. The aspx page then does an ajax post to a classic asp page which all it does is stored in our Sql 2008 DB. I can see in the database that the character is not stored correctly. For example the first name looks like Mª
where it should be Mª
.
When I then read that data and display it in a text box it is still displaying Mª
.
things I've tried:
<%@ Language=VBScript codepage=65001 %>
<% Response.Charset="UTF-8" %>
any other ideas? Do I need to go back into the database and fix the characters first or can this be done when I read the characters and display them?
Upvotes: 7
Views: 28320
Reputation: 11
Use always Server.HTMLEncode
in your pages for every text inside the HTML.
Remember that in ASP the character inside the ASP file is (or may be) the current default in the operating system. For example: Windows-1252 or CP-1252 (code page 1252).
So in constants inside code you shoud write:
text = "M" & Chr(170) 'M + feminine ordinal sign
All source file may contains only ASCII characters.
In all cases, you should use the HTML encoding in this way:
<input type="text" value="<%= Server.HTMLEncode(text & "") %>">
Result:
<input type="text" value="Mª">
Upvotes: 0
Reputation: 153
I had same problem when started using utf-8 on ASP, found that session.CodePage makes the difference. In classic ASP pages do always this first ASP declarations to ensure all page uses UTF-8 for data, forms, asp code, data received or sent.
<%@Language=VBScript CodePage = 65001%>
<%
Session.CodePage = 65001
Response.charset ="utf-8"
Session.LCID = 1033 'en-US
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Upvotes: 12
Reputation: 189357
What you are looking at is UTF-8. It's probably exactly as it should be, and the problem is that the tool you use for the looking is not handling the UTF-8 correctly, either because it cannot, or because it is not configured correctly.
Upvotes: 3