Progress® Telerik® Reporting R3 2017

XHTML Validation

The HtmlTextBox requires valid XHTML and you should make sure you provide such otherwise the HtmlTextBox would throw exception. To handle this exception or just check whether the HtmlTextBox would be able to handle the content you set as value, you should use the IsValidXhtml expressions function or XhtmlValidatorIsValidXhtml static method. Three possible approaches are listed below:

Validate Xhtml Using IsValidXhtml in Expression

Use the IsValidXhtml inside the HtmlTextBox Expression:

const string validXhtml = "<b>valid xhtml</b>.";
const string systemXhtml = "Provided html is not acceptable.";

Telerik.Reporting.HtmlTextBox txt = new Telerik.Reporting.HtmlTextBox();
txt.Value = string.Format("=Iif(IsValidXhtml('{0}'), '{0}', '{1}')", validXhtml, systemXhtml);

Validate Xhtml Using Event And IsValidXhtml

Use the IsValidXhtml inside the HtmlTextBox ItemDataBinding handler:

const string validXhtml = "<b>valid xhtml</b>.";
const string systemXhtml = "Provided html is not acceptable.";

Telerik.Reporting.HtmlTextBox txt = new Telerik.Reporting.HtmlTextBox();
txt.ItemDataBinding += delegate(object sender, EventArgs args)
    {
        Telerik.Reporting.Processing.HtmlTextBox procTxt = (Telerik.Reporting.Processing.HtmlTextBox)sender;
        if (Telerik.Reporting.Processing.XhtmlValidator.IsValidXhtml(validXhtml))
        {
            procTxt.Value = validXhtml;
        }
        else
        {
            procTxt.Value = systemXhtml;
        }
    };

Validate Xhtml Using Event And ValueError

Use a try-catch block to handle the exception:

const string invalidXhtml = "<b>invalid xhtml.";
const string systemXhtml = "Provided html is not acceptable.";

Telerik.Reporting.HtmlTextBox txt = new Telerik.Reporting.HtmlTextBox();
txt.ItemDataBinding += delegate(object sender, EventArgs args)
    {
        Telerik.Reporting.Processing.HtmlTextBox procTxt = (Telerik.Reporting.Processing.HtmlTextBox)sender;
        try
        {
            procTxt.Value = invalidXhtml;
            // html that will not be accepted
        }
        catch (Exception)
        {
            procTxt.Value = systemXhtml;
        }
    };