473,467 Members | 2,341 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

unicode textbox problem

OK I have some Chinese text in sql server column that looks like this:
12大专题调**解广东科*发展难题

This is unicode? Anyway, I put this data into a text area like this:
articleArea.InnerHtml = article.Text . . ..

and it works fine (shows chinese characters). But when I put this data into
a asp:textbox control, it just shows up as is... (12大&# etc...)

Can anyone tell me how to get the characters to appear correctly in the text
box?

Sep 26 '08 #1
9 14100
tparks69 <tp******@discussions.microsoft.comwrote:
OK I have some Chinese text in sql server column that looks like this:
12???????????????

This is unicode? Anyway, I put this data into a text area like this:
articleArea.InnerHtml = article.Text . . ..

and it works fine (shows chinese characters). But when I put this data into
a asp:textbox control, it just shows up as is... (12?&# etc...)

Can anyone tell me how to get the characters to appear correctly in the text
box?
Chances are it's because the text box is using a different font - and
one which doesn't contain those characters. I don't know if you can
specify fonts for text boxes, but that would be my line of enquiry if I
were you.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Sep 26 '08 #2


"Jon Skeet [C# MVP]" wrote:
tparks69 <tp******@discussions.microsoft.comwrote:
OK I have some Chinese text in sql server column that looks like this:
12???????????????

This is unicode? Anyway, I put this data into a text area like this:
articleArea.InnerHtml = article.Text . . ..

and it works fine (shows chinese characters). But when I put this data into
a asp:textbox control, it just shows up as is... (12?&# etc...)

Can anyone tell me how to get the characters to appear correctly in the text
box?

Chances are it's because the text box is using a different font - and
one which doesn't contain those characters. I don't know if you can
specify fonts for text boxes, but that would be my line of enquiry if I
were you.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Sep 26 '08 #3
I have the font specified as: style="font-family:Arial Unicode MS" but that
doesn't help. Also I found some code that works but the source data is in a
slightly different format than how I am getting it from SQL server:

So this works:

char[] chinese = {'\u6B22','\u8FCE','\u4F7F','\u7528','\u0020'};
txtHeadline.Text = new string(chinese);

text shows up as chinese characters in the textbox... but my data from SQL
server is in a different format... like this...

专 题 etc... what is this format, how can I convert it to '\u6B22'
etc...???

"Jon Skeet [C# MVP]" wrote:
tparks69 <tp******@discussions.microsoft.comwrote:
OK I have some Chinese text in sql server column that looks like this:
12???????????????

This is unicode? Anyway, I put this data into a text area like this:
articleArea.InnerHtml = article.Text . . ..

and it works fine (shows chinese characters). But when I put this data into
a asp:textbox control, it just shows up as is... (12?&# etc...)

Can anyone tell me how to get the characters to appear correctly in the text
box?

Chances are it's because the text box is using a different font - and
one which doesn't contain those characters. I don't know if you can
specify fonts for text boxes, but that would be my line of enquiry if I
were you.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Sep 26 '08 #4
tparks69 <tp******@discussions.microsoft.comwrote:
I have the font specified as: style="font-family:Arial Unicode MS" but that
doesn't help. Also I found some code that works but the source data is in a
slightly different format than how I am getting it from SQL server:

So this works:

char[] chinese = {'\u6B22','\u8FCE','\u4F7F','\u7528','\u0020'};
txtHeadline.Text = new string(chinese);

text shows up as chinese characters in the textbox... but my data from SQL
server is in a different format... like this...

? ? etc... what is this format, how can I convert it to '\u6B22'
etc...???
Okay, so if the problem is getting the data in the first place, read
this:

http://pobox.com/~skeet/csharp/debuggingunicode.html

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Sep 26 '08 #5
Try adding
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
or
<%@ CODEPAGE = 65001 %>
<% Session.CodePage = 65001 %>
<% Response.CodePage = 65001 %>

(not sure what version you are using)
Also, <%@ CODEPAGE %will also set Session/Response CodePage,
so there is no need to do it explicitely (just make sure you don't
call them with another value)

If the page has a header and a meta, make sure is also set to utf-8
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=utf-8">
a asp:textbox control, it just shows up as is... (12大&# etc...)
This tells us the encoding is messed-up, not the font.
A bad font would give you squares (missing glyph)
--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Sep 27 '08 #6
Jon, thanks for you replies. I looked at your links... there is a lot of
info there, I will continue to study this, but it hasn't really revealed any
solutions for me. Previously you wrote:
Okay, so if the problem is getting the data in the first place, read
this:
The problem isn't getting the data... I'm getting data from sql server in
some encoded format, but I don't know what it is... it starts with an
ampersand '&', then there is a '#' pound sign, then a 5 digit integer, then a
semi colon. I notice it gets translated when I post it exactly, so I'm
trying to descibe it here. If I put some spaces between it, a single
character looks like this (remove spaces):

& # 35843 ;

First of all, is this unicode?

Secondly, this is what I know about the problem:

1. I get the data in the above format from SQL server.
2. On an ASP.NET 2.0 webpage, if I move this data into a the innerHtml
property of a div tag for example, I see Chinese characters as expected, for
example:

articleArea.InnerHtml = article.NativeHeadline; //this works great!!!

3. If I move the same data into an asp:textbox, or an html input textbox, I
get the data exactly as it looks in SQL server with the ampersand, pound,
number, semicolon format. But I need this to show the Chinese characters.

4. Interstingly, if I cut and paste from the DIV in step 2, to the textbox,
the textbox shows the Chinese characters just fine... but this does not solve
the problem of course, just an interesting note.

5. I did try changing the font to MS Arial Unicode also didn't work

6. Another interesting note, a gridview column will display the data just
fine too!

7. Is there some conversion I can do in c# server side to get it to work?
I know for example, that if the data is in this format:

char[] chinese = {'\u6B22','\u8FCE','\u4F7F','\u7528','\u0020'};

and I move this to the textbox, the data also shows as expected. But how to
get the ampersand, pound, number, semicolon translated to the above?

Any other ideas for me are appreciated, I just need to know how to get the
textbox control to show Chinese and not weird codes.

Thanks

"Jon Skeet [C# MVP]" wrote:
tparks69 <tp******@discussions.microsoft.comwrote:
I have the font specified as: style="font-family:Arial Unicode MS" but that
doesn't help. Also I found some code that works but the source data is in a
slightly different format than how I am getting it from SQL server:

So this works:

char[] chinese = {'\u6B22','\u8FCE','\u4F7F','\u7528','\u0020'};
txtHeadline.Text = new string(chinese);

text shows up as chinese characters in the textbox... but my data from SQL
server is in a different format... like this...

? ? etc... what is this format, how can I convert it to '\u6B22'
etc...???

Okay, so if the problem is getting the data in the first place, read
this:

http://pobox.com/~skeet/csharp/debuggingunicode.html

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Sep 29 '08 #7
tparks69 <tp******@discussions.microsoft.comwrote:
Jon, thanks for you replies. I looked at your links... there is a lot of
info there, I will continue to study this, but it hasn't really revealed any
solutions for me. Previously you wrote:
Okay, so if the problem is getting the data in the first place, read
this:

The problem isn't getting the data... I'm getting data from sql server in
some encoded format, but I don't know what it is... it starts with an
ampersand '&', then there is a '#' pound sign, then a 5 digit integer, then a
semi colon.
How are you viewing that? My guess is that you've got it in XML
somewhere - those sound like XML character entities.

I strongly recommend that you write a small *console* application which
fetches the string and dumps them out as
I notice it gets translated when I post it exactly, so I'm
trying to descibe it here. If I put some spaces between it, a single
character looks like this (remove spaces):

& # 35843 ;

First of all, is this unicode?
It's an XML character reference.
Secondly, this is what I know about the problem:

1. I get the data in the above format from SQL server.
Is the data meant to contain XML, or are you asking for it in XML?
2. On an ASP.NET 2.0 webpage, if I move this data into a the innerHtml
property of a div tag for example, I see Chinese characters as expected, for
example:

articleArea.InnerHtml = article.NativeHeadline; //this works great!!!

3. If I move the same data into an asp:textbox, or an html input textbox, I
get the data exactly as it looks in SQL server with the ampersand, pound,
number, semicolon format. But I need this to show the Chinese characters.
The difference is that when you specify the InnerHtml property, you're
specifying HTML, which includes the character references.

Put it this way: if your string were actually "<b>hello</b>" then by
specifying it as InnerHtml you'd get "hello" in bold, whereas as the
text for a textbox you'd get "<b>hello</b>".
4. Interstingly, if I cut and paste from the DIV in step 2, to the textbox,
the textbox shows the Chinese characters just fine... but this does not solve
the problem of course, just an interesting note.

5. I did try changing the font to MS Arial Unicode also didn't work

6. Another interesting note, a gridview column will display the data just
fine too!

7. Is there some conversion I can do in c# server side to get it to work?
I know for example, that if the data is in this format:

char[] chinese = {'\u6B22','\u8FCE','\u4F7F','\u7528','\u0020'};

and I move this to the textbox, the data also shows as expected. But how to
get the ampersand, pound, number, semicolon translated to the above?
You need to find out why you're getting the character reference to
start with. Where did the data come from? Is it meant to be plaintext,
or XML already?

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Sep 29 '08 #8
I figured out the solution. I put a HttpUtility.HtmlDecode on the string
coming from the DB and got the correct output.

The data did come from XML before being put in the DB, and probably a web
page before that, so it must have been HTML encoded at some point I'm
guessing.
"Jon Skeet [C# MVP]" wrote:
tparks69 <tp******@discussions.microsoft.comwrote:
Jon, thanks for you replies. I looked at your links... there is a lot of
info there, I will continue to study this, but it hasn't really revealed any
solutions for me. Previously you wrote:
Okay, so if the problem is getting the data in the first place, read
this:
The problem isn't getting the data... I'm getting data from sql server in
some encoded format, but I don't know what it is... it starts with an
ampersand '&', then there is a '#' pound sign, then a 5 digit integer, then a
semi colon.

How are you viewing that? My guess is that you've got it in XML
somewhere - those sound like XML character entities.

I strongly recommend that you write a small *console* application which
fetches the string and dumps them out as
I notice it gets translated when I post it exactly, so I'm
trying to descibe it here. If I put some spaces between it, a single
character looks like this (remove spaces):

& # 35843 ;

First of all, is this unicode?

It's an XML character reference.
Secondly, this is what I know about the problem:

1. I get the data in the above format from SQL server.

Is the data meant to contain XML, or are you asking for it in XML?
2. On an ASP.NET 2.0 webpage, if I move this data into a the innerHtml
property of a div tag for example, I see Chinese characters as expected, for
example:

articleArea.InnerHtml = article.NativeHeadline; //this works great!!!

3. If I move the same data into an asp:textbox, or an html input textbox, I
get the data exactly as it looks in SQL server with the ampersand, pound,
number, semicolon format. But I need this to show the Chinese characters.

The difference is that when you specify the InnerHtml property, you're
specifying HTML, which includes the character references.

Put it this way: if your string were actually "<b>hello</b>" then by
specifying it as InnerHtml you'd get "hello" in bold, whereas as the
text for a textbox you'd get "<b>hello</b>".
4. Interstingly, if I cut and paste from the DIV in step 2, to the textbox,
the textbox shows the Chinese characters just fine... but this does not solve
the problem of course, just an interesting note.

5. I did try changing the font to MS Arial Unicode also didn't work

6. Another interesting note, a gridview column will display the data just
fine too!

7. Is there some conversion I can do in c# server side to get it to work?
I know for example, that if the data is in this format:

char[] chinese = {'\u6B22','\u8FCE','\u4F7F','\u7528','\u0020'};

and I move this to the textbox, the data also shows as expected. But how to
get the ampersand, pound, number, semicolon translated to the above?

You need to find out why you're getting the character reference to
start with. Where did the data come from? Is it meant to be plaintext,
or XML already?

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Sep 30 '08 #9
Hi all,

I wanted to display Unicode characters on some controls using C# (I use
Ms Visual C# 2005 Express Edition).

I've found problem when I wanted to display the Unicode character in
controls beside rich text box (such as label, button, toolstripbutton,
etc).

The Unicode can be displayed correctly using rich text box. However in
other controls many characters are shown in as "box".

E.g. the display of Unicode with hex value 0100 8888 in button will be
"Ā" and box, where in rich text box is "Ā袈" (correct).

Anyone can help me on this? I appreciate any help...

Thanks and Regards,
David

*** Sent via Developersdex http://www.developersdex.com ***
Oct 1 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kathy | last post by:
Hi! Is there any way I can create a unicode object from the unicode code itself. I extract the code from a file and need to create a unicode object that represents the corresponding character....
2
by: garykpdx | last post by:
Every time I think I understand unicode, I prove I don't. I created a variable in interactive mode like this: s = u'' where this character is the a-umlaut that worked alright. Then I encoded...
1
by: Andrew McCall | last post by:
Hi Folks, I am having a problem with a forms entry using Unicode characters, specifically "smart-quotes". Under Microsoft PWS and MS-SQL 7.0 it works fine and I get the Unicode characters, such...
1
by: Klaubator | last post by:
Hi, A simple task is driving me crazy, just can figure out how to programatically write unicode characters to a SVG (XML) document. With an editor it is easy to write Unicode characters like...
0
by: charles hamm | last post by:
I have an app that worked fine under MBCS in VC6 but is broken now under unicode in VC7. The app writes text files using CStdioFile. A standard doc/view pair of classes allows the user to read the...
8
by: Richard Schulman | last post by:
Sorry to be back at the goodly well so soon, but... ....when I execute the following -- variable mean_eng_txt being utf-16LE and its datatype nvarchar2(79) in Oracle: cursor.execute("""INSERT...
4
by: Petr Jakes | last post by:
Hi, I am using Python 2.4.3 on Fedora Core4 and "Eric3" Python IDE .. Below mentioned code works fine in the Eric3 environment. While trying to start it from the command line, it returns: ...
0
by: santhescript01 | last post by:
Unicode to non unicode conversion problem -------------------------------------------------------------------------------- Hi All, I am using C dll in macro which converts Unicode data to...
1
by: Eric S. Johansson | last post by:
I'm having a problem (Python 2.4) converting strings with random 8-bit characters into an escape form which is 7-bit clean for storage in a database. Here's an example: body =...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.