[RESOLVED] Display special characters in text
I have created a series of buttons in C# and would like to make sure their text, which consists of special characters, is displayed properly in every browser. I tried using HTML characters as text but these were read as a string as opposed to as HTML. How can I do this?
protected void CreateButton()
{
btnSkill = new Button();
btnSkill.Text = "display this German symbol: ä"; // PROBLEM HERE!
}
Thank you very much in advance!
1 Attachment(s)
Re: Display special characters in text
Hello,
I tried something similar on a label. I've attached a screen shot. What is going wrong with yours? Here's my code:
Code:
protected void Page_PreRender(object sender, EventArgs e)
{
testLabel.Text = "display this German symbol: ä";
}
Re: Display special characters in text
Quote:
Originally Posted by
stephsh
protected void CreateButton()
{
btnSkill = new Button();
btnSkill.Text = "display this German symbol: ä"; // PROBLEM HERE!
}
Looks like you want tou create a new button, but it is never added to the Page.Controls
Code:
Page.Controls.Add(btnSkill);
1 Attachment(s)
Re: Display special characters in text
Thank you for your answers.
My button successfully displays text, it just doesn't convert the HTML code to text. It is strange that nelo's does.... Here is a screenshot:
Re: Display special characters in text
Hi stephsh,
I've also tried it in firefox without any problem. Do you mind posting the exact portion of the code you have? I'll try it out on my side.
1 Attachment(s)
Re: Display special characters in text
I am going to have a problem posting my full code since I am importing the text as a string from a Webservice which in turns imports it from a database.
This is the method which generates the buttons' text:
Code:
protected void CreateTblMainSkill()
{
int i = 0;
// Creates a cell with a skill in each row
foreach(object skill in criterium)
{
btnSkill = new Button();
cellSkill = new TableCell();
rowSkill = new TableRow();
btnSkill.ID = Convert.ToString(criterium[i].ID);
btnSkill.Text = criterium[i].Skill; // PROBLEM LIES HERE!!!!!
btnSkill.BackColor = System.Drawing.Color.Transparent;
btnSkill.BorderColor = System.Drawing.Color.Transparent;
cellSkill.Controls.Add(btnSkill);
rowSkill.Controls.Add(cellSkill);
// On button click display side table for desired skill
btnSkill.Click += new EventHandler(btnSkill_CheckedChanged);
// For every skill add rbtn for each ENumGrade
for (int c = 0; c < eNumGradesList.Length; c++)
{
cellRbtn = new TableCell();
rbtnSkill = new RadioButton();
rbtnSkill.ID = Convert.ToString(criterium[i].ID) + "eNumGrade" + c;
rbtnSkill.Checked = false;
rbtnSkill.GroupName = Convert.ToString(criterium[i].Skill);
cellRbtn.Controls.Add(rbtnSkill);
cellRbtn.BorderColor = System.Drawing.Color.Blue;
rowSkill.Controls.Add(cellRbtn);
}
// Add the following rows to the stage
tblMain.Rows.Add(rowSkill);
i++;
}
}
The skill name to be displayed on the button (i.e. criterium[i].Skill) is generated here:
Code:
protected void GetCriterium()
{
try
{
criterium = WebServiceConnection.webService.getAllCriteria();
}
catch (UnauthorizedAccessException)
{
Azubiportal.ErrorPage.SetError("UnauthorizedAccessException");
errorPage.DisplayErrorMsg();
}
catch (IndexOutOfRangeException)
{
Azubiportal.ErrorPage.SetError("IndexOutOfRangeException");
errorPage.DisplayErrorMsg();
}
catch (Exception)
{
errorPage.DisplayErrorMsg();
}
}
In the database the skill names are displayed as nvarchar(50) under the field name KENNTNISSE as follows (check screenshot):
Re: Display special characters in text
Ok...it looks like the button behaves differently from a label. Try this...
Code:
protected void Page_PreRender(object sender, EventArgs e)
{
String text = "display this German symbol: ä";
testButton2.Text = Server.HtmlDecode(text);
}
Re: Display special characters in text