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

Difficulty with dynamically reporting HTML data

5 Answers 408 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 13 Jul 2011, 07:00 PM
Hello.

I have a report which we are rendering as a PDF. This report has one HTMLTextBox, which we wish to use to display the contents of an HTML email. (I am using 2010 Q3).

I'm finding that I can successfully set HTML into the HTMLTextbox in the designer, and have the HTML display in the report. However, if I try to set the HTML into the textbox in my databinding function, the report still shows the data entered in the designer, it has not been overriden with the data from the databinding function. Having no data in the HTMLTextbox in the designer does not change the behavior; in that case in the report the textbox will be empty

So, referencing the code below, the generated report is displaying 'hard coded paragraph", rather than "my paragraph". I have verified that the textBoxContents_ItemDataBound function is being called, that the bodytextbox variable is NOT null, and that when the function exits the bodytextbox.Value is still equal to the HTML set in the method.

Here are some bits of code that I think might be relevant. Thanks for your help!

        private void InitializeComponent()
        {
            this.textBoxContents.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(0.700118362903595D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(1.2142907381057739D, Telerik.Reporting.Drawing.UnitType.Inch));
            this.textBoxContents.Name = "textBoxContents";
            this.textBoxContents.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.7998027801513672D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.28570938110351562D, Telerik.Reporting.Drawing.UnitType.Inch));
            this.textBoxContents.Value = "<html><p>hard coded paragraph.</p></html>";
            this.textBoxContents.ItemDataBound += new System.EventHandler(this.textBoxContents_ItemDataBound);
      }
 
   private Telerik.Reporting.HtmlTextBox textBoxContents;

        private void textBoxContents_ItemDataBound(object sender, EventArgs e)
        {
            Telerik.Reporting.Processing.HtmlTextBox bodytextbox = sender as
                Telerik.Reporting.Processing.HtmlTextBox;
            if (bodytextbox != null)
                bodytextbox.Value = "<html><p>My paragraph.</p></html>";
        }

5 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 14 Jul 2011, 04:54 PM
Hello Mark,

You are correct, in the HtmlTextBox.ItemDataBound you can't modify the HtmlTextBox.Value property because it's too late for additional HTML parsing operations that may cause validation errors. Generally for modifying the HtmlTextBox value our suggestion is to set a design time expression that includes an user function. Generally user functions allow you to extend the default behavior of the Telerik Reporting engine. Give it a try and let us know how it goes and if you need additional assistance on the topic we will appreciate if you elaborate further on your scenario.

Best wishes,
Peter
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Mark
Top achievements
Rank 1
answered on 14 Jul 2011, 05:50 PM
Thanks for the assistance, I'll try that ASAP!
0
Mark
Top achievements
Rank 1
answered on 14 Jul 2011, 09:57 PM
Okay, so that worked, but I have a related question.

First, a little more information. I am, in a PDF report, displaying an HTML email. We have NO direct control over the HTML generated, we just need to report it. Here is an example:

We should but I cant find it in the list.<br><br><div class="gmail_quote">
On Wed, Mar 9, 2011 at 11:34 AM, Mr. Tester 
<span dir="ltr">&lt;<a href="mailto:mpetester@gmail.com">mpetester@gmail.com</a>&gt;</span> 
wrote:<br><blockquote class="gmail_quote" 
style="margin: 0pt 0pt 0pt 0.8ex; 
border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Do you know if we surt the original droid?<br></blockquote></div><br>

Now, sometimes we are getting an red error box displayed in the report, because Telerik did not like something about the HTML (an unclosed tag, or formatting value it did not like, for example). I understand there is nothing we can do about this, but I am wondering if there is some way my code can be informed that the HTML rendering will fail in advance. Then, perhaps, I could replace the rather technical, bright red error message with a nice calm message along the lines of "Unable to render this HTML", or something else.

In my report, each email data record is being displayed as a detail item in the report. When detail_ItemDataBinding is called for the detail record, I load and save the html that will be displayed. The HtmlTextBox has a expression that results in my user function GetContentsHTML being called; it returns the HTML data to be displayed in the HtmlTextBox (as suggested above by Telerik). Code snippets follow...

Thanks for your help,
Mark

private void InitializeComponent()
{
    this.textBoxContents.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(0.00039418539381586015D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(1.500433087348938D, Telerik.Reporting.Drawing.UnitType.Inch));
    this.textBoxContents.Name = "textBoxContents";
    this.textBoxContents.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(6.4995269775390625D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.28570938110351562D, Telerik.Reporting.Drawing.UnitType.Inch));
    this.textBoxContents.Value = "=GetContentsHTML()";
 
}
 
 
private static string _htmlString;
 
private void detail_ItemDataBinding(object sender, EventArgs e)
{
    _htmlString = "<html>no data</html>";
    MPEDataCache.MPEDataCacheDef.EmailRow rowdata = null;
 
    Telerik.Reporting.Processing.DetailSection dSection = sender as Telerik.Reporting.Processing.DetailSection;
    if (dSection == null)
        return;
 
    System.Data.DataRowView rowView = dSection.DataObject.RawData as System.Data.DataRowView;
    if (rowView == null)
        return;
 
    rowdata = rowView.Row as MPEDataCache.MPEDataCacheDef.EmailRow;
    if (rowdata == null)
        return;
 
    if (rowdata.IsContentsNull())
        return;
 
    _htmlString = rowdata.Contents;
}
 
public static string GetContentsHTML()
{
    return _htmlString;
}
0
Peter
Telerik team
answered on 15 Jul 2011, 02:56 PM
Hi Mark,

To validate your HTML you can use HtmlTextBox.IsValidXhtml Method with the following user function and embedded expression:

public static bool IsValidxHTML(Processing.HtmlTextBox htmlTextBox, string value)
{
    if (htmlTextBox.IsValidXhtml(value))
        return true;
 
    return false;
}

{IIF(IsValidxHTML(ReportItem,Fields.MyField),Fields.MyField, "<b>Invalid HTML</b>"}
Greetings,
Peter
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Mark
Top achievements
Rank 1
answered on 15 Jul 2011, 05:04 PM
Thanks, that is working well for me!
Tags
General Discussions
Asked by
Mark
Top achievements
Rank 1
Answers by
Peter
Telerik team
Mark
Top achievements
Rank 1
Share this question
or