Special Characters within a Textbox Value Clause

6 posts, 1 answers
  1. Tom
    Tom avatar
    12 posts
    Member since:
    Jun 2013

    Posted 27 Apr Link to this post

    I have a report that gives the nutrient breakdown of a feed ingredient. Sometimes the users in the lab will name the ingredient such that it references other work they are performing which typically results in the use of special characters. When they use "{}" the report viewer throws an exception.

     

    I know that there is a workaround in C# to resolve these conflicts but how do I get around this in the Telerik Reporting system (short of scrubbing the data to remove the offending character?) The Value assignment in the example code causes this issue.

    Example code:

                <TextBox Width="1.78in"
                         Height="0.17in"
                         Left="0in"
                         Top="1.96in"
                         Value="{35 DM NDF M}"
                         Name="lblDietSummary_Title_0">
                  <Style Visible="True"
                         Color="Black"
                         TextAlign="Left"
                         VerticalAlign="Middle">
                  <Font  Name="Arial"
                         Size="9pt"
                         Bold="True" />
                  </Style>
                </TextBox>

     

  2. Tom
    Tom avatar
    12 posts
    Member since:
    Jun 2013

    Posted 27 Apr in reply to Tom Link to this post

    For further clarification, this report item is generated in code:

    Text box definition &  value assignment:

        tbTitle.Name = "lblDietSummary_Title_0);
        tbTitle.Value = SpecialCharacterScrubber(myDietSummary["Ingredient"].ToString());

    Attempt to clean up the string value:

            private string SpecialCharacterScrubber(string checkField)
            {
                checkField = checkField.Replace("{", "&#123;");
                checkField = checkField.Replace("}", "&#125;");
                return checkField;
            }

    which resulted in "&#123;35 DM NDF M&#125;"  being printed on the report. Not the desired result.

  3. DevCraft banner
  4. Answer
    Katia
    Admin
    Katia avatar
    308 posts

    Posted 28 Apr Link to this post

    Hello Tom,

    As curly brackets are used by the engine to identify embedded expressions they should be escaped with double brackets: {{ or }}.

    For example, textBox1.Value = "{{35 DM NDF M}}".


    Regards,
    Katia
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Tom
    Tom avatar
    12 posts
    Member since:
    Jun 2013

    Posted 28 Apr in reply to Katia Link to this post

    Thanks! That took care of it.
  6. Greg
    Greg avatar
    3 posts
    Member since:
    May 2016

    Posted 02 May in reply to Tom Link to this post

    Hey Tom.  You might want to try an HTML textbox and escape the characters.  I just created an HTML textbox with a square.

    <span style='color: green;'>&#9632;</span> Category

  7. Tom
    Tom avatar
    12 posts
    Member since:
    Jun 2013

    Posted 03 May in reply to Greg Link to this post

    I just created a method to resolve it.

            private string SpecialCharacterScrubber(string checkField)
            {
                checkField = checkField.Replace("{", "{{");
                checkField = checkField.Replace("}", "}}");
                return checkField;
            }

    Thanks for the suggestion just the same.

     

     

Back to Top
DevCraft banner