<%@dotnet.itags.org.Page Culture="fr-FR" UICulture="fr-FR" ResponseEncoding="utf-8"%>or in the web.config:
<configuration>
<system.web>
<globalization responseEncoding="utf-8" />
</system.web>
</configuration>
However, I've been unable to set the encoding of the response object programmatically.
Does anyone know whether this can be done and, if so, how?
On a related topic, can anyone explain why prominent XHTML sites, such aswww.zeldman.com, use ASCII encoding (ISO-8859-1) rather than Unicode? If I am building XHTML compliant sites, which encoding should I be using? I've seen varying opinions, includingUS-ASCII. I don't have much understanding of encoding, so I cannot yet make an informed decision.
Thanks to anyone who can help ...Have you triedResponse.ContentEncoding?
Yep. I can use that to specify UTF8 or Unicode (or any other validSystem.Text.Encoding property).
However, I cannot achieve ISO-8859-1 encoding (it is not one of the available properties of that class).
I can do so declaratively:
<%@. Page Language="C#" inherits="e3.Web.UI.Page" Debug="true" ResponseEncoding="ISO-8859-1" %>
But I'm still stuck on doing this programmatically...
Actually, I figured it out.
I was following the same path as you suggested ... trying to change the encoding of the Response object.
The answer was under my nose the whole time ... the ResponseEncoding parameter in the Page declaration sets theSystem.Web.UI.Page.ResponseEncoding property.
Hence, for anyone who follows this later ... this is how to change the encoding programmatically in codebehind:
namespace e3.Web.UI
{
public class Page : System.Web.UI.Page
{
public void Page_Load( object Sender, EventArgs e )
{
this.ResponseEncoding = "ISO-8859-1";
}
}
}
It's odd why there is a difference - I would have expected the same problem. Well at least you've found your solution.
> I would have expected the same problem
Well, not thesame problem ...
Response.ContentEncoding is of typeEncoding
whereasPage.ResponseEncoding is of type string (hence I could set it to a value not available in the Encoding class).
> It's odd why there is a difference
Sure is. I don't understand the relationship (if any) between Response.ContentEncoding and Page.ResponseEncoding.
More baffling ... the documentation for Page.ResponseEncoding states:
"This member supports the .NET Framework infrastructure and is not intended to be used directly from your code."
Still, a solution that works is a working solution :)
I knew that Page.ResponseEncoding is of type String. What I meant was that I would have expected it to be of type Encoding aswell. But having said that, I don't understand the relationship either.
0 comments:
Post a Comment