This is a migrated thread and some comments may be shown as answers.

Special Characters within a Textbox Value Clause

7 Answers 210 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 27 Apr 2016, 01:31 PM

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>

 

7 Answers, 1 is accepted

Sort by
0
Tom
Top achievements
Rank 1
answered on 27 Apr 2016, 02:37 PM

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.

0
Accepted
Katia
Telerik team
answered on 28 Apr 2016, 03:22 PM
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
0
Tom
Top achievements
Rank 1
answered on 28 Apr 2016, 03:48 PM
Thanks! That took care of it.
0
Greg
Top achievements
Rank 1
answered on 02 May 2016, 10:57 PM

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

0
Tom
Top achievements
Rank 1
answered on 03 May 2016, 01:15 PM

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.

 

 

0
Chris
Top achievements
Rank 1
Veteran
Iron
answered on 03 Feb 2021, 09:12 AM
HI

I know how to escape curly brackets - { } : 

Embedded Expressions
https://docs.telerik.com/reporting/expressions-embedded

But how to escape square brackets and leading equal sign for TextBox.Value ? 

MyTextBox.Value = "[=abdominal fullness ...]";

*Plain text "[=abdominal fullness ...]".

Error message : 

Value expression [=abdominal fullness ...] is not valid:
Missing operator before 'fullness' operand.

ExceptionType: System.Exception
  at Telerik.Reporting.Processing.ExpressionExtractor.ExtractEmbeddedExp(String expression, String sourceName, String property)
  at Telerik.Reporting.Processing.ExpressionExtractor.VisitTextBox(TextBox item)
  at Telerik.Reporting.TextBox.Accept(ReportItemVisitor visitor)
  at Telerik.Reporting.Processing.ExpressionExtractor.Visit(ReportItemBase item)
  at Telerik.Reporting.ReportItemVisitor.VisitExtension(ReportItemBase item)
  at Telerik.Reporting.Processing.ExpressionExtractor.Visit(ReportItemBase item)
  at Telerik.Reporting.ReportItemVisitor.VisitExtension(ReportItemBase item)
  at Telerik.Reporting.Processing.ExpressionExtractor.Visit(ReportItemBase item)
  at Telerik.Reporting.Processing.ExpressionExtractor.VisitAllExpressions(ReportItemBase item)

Best regards

Chris
0
Neli
Telerik team
answered on 08 Feb 2021, 09:51 AM

Hi Chris,

I have tested using [=abdominal fullness ...] as a Value of a textbox, however, I am afraid I was not able to reproduce the problem. Please, check the attached report.

Basically, when the value starts with =, it will be treated as an expression. To escape the equal sign in the Standalone designer, you can use the expression below:

= ("=AAAA")

Can you please send us a sample report that reproduces the problem, so I can test it locally? I will be looking forward to receiving an update from you.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
General Discussions
Asked by
Tom
Top achievements
Rank 1
Answers by
Tom
Top achievements
Rank 1
Katia
Telerik team
Greg
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Veteran
Iron
Neli
Telerik team
Share this question
or