Trouble displaying Japanese text with aspx

P

pardesiya

Friends,

I am having trouble displaying Japanese text within a textbox (or
anywhere else) in an aspx page with .net 2.0 framework. Initial
default text in Japanese displays perfectly but when I attempt to
change the text following a button-click event, it displays as junk.

I have tried setting the globalization tag in the web.config file but
that does not help eiter.
<globalization requestEncoding="UTF-8" responseEncoding="UTF-8"
fileEncoding="UTF-8"/>

I should mention that the problem does not happen in my development pc
where I am using the Visual Web Developer 2005 IDE. It happens only
when I deploy the files to the actual IIS webserver on Windows 2000.

Would greatly appreciate any help.

Here's what I have:

1. TestJP.aspx contains:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="TestJP.aspx.cs" Inherits="TestJP" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test JP</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtJP" runat="server" Height="101px"
Width="374px">Default Japanese Text</asp:TextBox>
<br />
<asp:Button ID="cmdJP" runat="server" Text="Change Text"
OnClick="cmdJP_Click" />
</div>
</form>
</body>
</html>

2. TestJP.aspx.cs contains:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class TestJP : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void cmdJP_Click(object sender, EventArgs e)
{
txtJP.Text = "New Japanese text";
}
}
 
G

Guest

Friends,

I am having trouble displaying Japanese text within a textbox (or
anywhere else) in an aspx page with .net 2.0 framework. Initial
default text in Japanese displays perfectly but when I attempt to
change the text following a button-click event, it displays as junk.

I have tried setting the globalization tag in the web.config file but
that does not help eiter.
<globalization requestEncoding="UTF-8" responseEncoding="UTF-8"
fileEncoding="UTF-8"/>

I should mention that the problem does not happen in my development pc
where I am using the Visual Web Developer 2005 IDE. It happens only
when I deploy the files to the actual IIS webserver on Windows 2000.

Would greatly appreciate any help.

Here's what I have:

1. TestJP.aspx contains:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="TestJP.aspx.cs" Inherits="TestJP" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test JP</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtJP" runat="server" Height="101px"
Width="374px">Default Japanese Text</asp:TextBox>
<br />
<asp:Button ID="cmdJP" runat="server" Text="Change Text"
OnClick="cmdJP_Click" />
</div>
</form>
</body>
</html>

2. TestJP.aspx.cs contains:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class TestJP : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void cmdJP_Click(object sender, EventArgs e)
{
txtJP.Text = "New Japanese text";
}



}- Hide quoted text -

- Show quoted text -

Go to File - Save .aspx As - point to Save and select Save with
Encoding... What encoding do you use to save the file?
 
G

Guest

Go to File - Save .aspx As - point to Save and select Save with
Encoding... What encoding do you use to save the file?- Hide quoted text -

Wait... you have to check the encoding for your TestJP.aspx.cs file.
It seems that it saved in a different encoding...
 
P

pardesiya

Alexey thanks a lot for your prompt suggestion. That worked!
TestJP.aspx.cs and TestJP.aspx were saved with Shift_JIS. Changed
that to UTF-8 and it works fine!

I have a second question which is related. I query data into a dataset
and display the result in the same text box but it appears junk. Is
there any way I should set the charset of the DataSet? The database is
probably encoded with Unicode.

DataSet dsTables = new DataSet();
dsTables = <code to get data from database>
txtJP.Text = dsTables.Tables[0].Rows[0]["japanese_name"].ToString();
 
G

Guest

Alexey thanks a lot for your prompt suggestion. That worked!
TestJP.aspx.cs and TestJP.aspx were saved with Shift_JIS. Changed
that to UTF-8 and it works fine!

I have a second question which is related. I query data into a dataset
and display the result in the same text box but it appears junk. Is
there any way I should set the charset of the DataSet? The database is
probably encoded with Unicode.

DataSet dsTables = new DataSet();
dsTables = <code to get data from database>
txtJP.Text = dsTables.Tables[0].Rows[0]["japanese_name"].ToString();

Where data came from? Did you do that from your asp.net application?

It seems that the data encoded in other format...

Try to change encoding of your result page, in IE right click,
Encoding - Shift_JIS (or any other)
 
P

pardesiya

Thanks Alexey. Yes, I'm getting the data from asp.net application.
But changing the encoding in IE doesnt seem to help. As you mention
maybe the data is encoded differently. Probably I should post this as
a separate thread.

using System.Data.OleDb;

OleDbConnection OledbConn = new OleDbConnection();
OleDbDataAdapter OledbDataAdap = new OleDbDataAdapter();
DataSet OleDbDS = new DataSet();

OledbConn.ConnectionString = <connection string to Sybase
database>;
OledbConn.Open();

OledbDataAdap.SelectCommand = new OleDbCommand("select
japanese_name from ... ", OledbConn);
OledbDataAdap.Fill(OleDbDS);
OledbConn.Close();

return OleDbDS;
 
G

Guest

Thanks Alexey. Yes, I'm getting the data from asp.net application.
But changing the encoding in IE doesnt seem to help. As you mention
maybe the data is encoded differently. Probably I should post this as
a separate thread.

using System.Data.OleDb;

OleDbConnection OledbConn = new OleDbConnection();
OleDbDataAdapter OledbDataAdap = new OleDbDataAdapter();
DataSet OleDbDS = new DataSet();

OledbConn.ConnectionString = <connection string to Sybase
database>;
OledbConn.Open();

OledbDataAdap.SelectCommand = new OleDbCommand("select
japanese_name from ... ", OledbConn);
OledbDataAdap.Fill(OleDbDS);
OledbConn.Close();

return OleDbDS;

Sorry, I think I was not clear. I'm interesting in the code which
stored the data in the database. I guess, you have a kind of web form
with fields and submit button which fires the code-behind action. This
form has to be in UTF encoded

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

not sure about a code (want to see it first)

and your database should support that encoding.

Actually, if you browse the database using a shell, do you see the
correct characters? Are you able to insert any data in Japanese (using
a shell) and see that text on the website?
 
P

pardesiya

Ok I understand what you mean. Actually I am not sure about how the
data is stored in the database. The people who maintain the database
have some kind of tool or database application to insert the data. I
only try to retrieve some data using an oledb connection in my asp.net
form.

But I am able to browse the database using Microsoft Query and see the
Japanese data correctly. I can even download the correct data into
Excel. I dont have permission to insert data so cannot check that
part.
 
G

Guest

Ok I understand what you mean. Actually I am not sure about how the
data is stored in the database. The people who maintain the database
have some kind of tool or database application to insert the data. I
only try to retrieve some data using an oledb connection in my asp.net
form.

But I am able to browse the database using Microsoft Query and see the
Japanese data correctly. I can even download the correct data into
Excel. I dont have permission to insert data so cannot check that
part.

1. Check the existing output. Maybe it will give you idea about
encoding.

2. Try to encode

System.Text.Encoding en1 = System.Text.Encoding.Unicode;
System.Text.Encoding en2 = System.Text.Encoding.UTF8;
txtJP.Text = en2.GetString(en1.GetBytes(dsTables.Tables[0].Rows[0]
["japanese_name"].ToString()));

or

System.Text.Encoding en1 =
System.Text.Encoding.Encoding.GetEncoding("Shift_JIS"); // or any
other standard JP-encoding
System.Text.Encoding en2 = System.Text.Encoding.UTF8;
txtJP.Text = en2.GetString(en1.GetBytes(dsTables.Tables[0].Rows[0]
["japanese_name"].ToString()));

3. Check code page of your database

4. Contact db-developers :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top