[RESOLVED] Display special characters in text
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: [RESOLVED] Display special characters in text

Hybrid View

  1. #1
    Join Date
    Jan 2010
    Posts
    130

    [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!

  2. #2
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    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: ä"; 
        }
    Attached Images Attached Images  

  3. #3
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Display special characters in text

    Quote Originally Posted by stephsh View Post
    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);

  4. #4
    Join Date
    Jan 2010
    Posts
    130

    Question 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:
    Attached Images Attached Images  

  5. #5
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    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.

  6. #6
    Join Date
    Jan 2010
    Posts
    130

    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):
    Attached Images Attached Images  

  7. #7
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    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: &auml;";
            testButton2.Text = Server.HtmlDecode(text);
        }

  8. #8
    Join Date
    Jan 2010
    Posts
    130

    Talking Re: Display special characters in text

    Thank you!!!!!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center