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 method of the HtmlTextBox processing instance. Three possible
approaches are listed below:
Validate Xhtml Using Event And IsValidXhtml
Use the IsValidXhtml inside the HtmlTextBox ItemDataBinding handler:
CopyC#
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 (procTxt.IsValidXhtml(validXhtml))
{
procTxt.Value = validXhtml;
}
else
{
procTxt.Value = systemXhtml;
}
};
CopyVB.NET
Dim txt As New Telerik.Reporting.HtmlTextBox()
AddHandler txt.ItemDataBinding, AddressOf MyEventHandler
Const validXhtml As String = "<b>valid xhtml</b>."
Const systemXhtml As String = "Provided html is not acceptable."
Private Sub MyEventHandler(ByVal sender As Object, ByVal e As EventArgs)
Dim procTxt As Telerik.Reporting.Processing.HtmlTextBox = DirectCast(sender, Telerik.Reporting.Processing.HtmlTextBox)
If procTxt.IsValidXhtml(validXhtml) Then
procTxt.Value = validXhtml
Else
procTxt.Value = systemXhtml
End If
End Sub
Validate Xhtml Using IsValidXhtml in Expression
Use the IsValidXhtml inside the HtmlTextBox Expression:
CopyC#
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(ReportItem.IsValidXhtml('{0}'), '{0}', '{1}')", validXhtml, systemXhtml);
CopyVB.NET
Const validXhtml As String = "<b>valid xhtml</b>."
Const systemXhtml As String = "Provided html is not acceptable."
Dim txt As New Telerik.Reporting.HtmlTextBox()
txt.Value = String.Format(, validXhtml, systemXhtml)
Validate Xhtml Using Event And ValueError
Use a try-catch block to handle the exception:
CopyC#
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;
}
catch (Exception)
{
procTxt.Value = systemXhtml;
}
};
CopyVB.NET
Dim txt As New Telerik.Reporting.HtmlTextBox()
AddHandler txt.ItemDataBinding, AddressOf ValueErrorHandler
Const invalidXhtml As String = "<b>invalid xhtml."
Const defaultXhtml As String = "Provided html is not acceptable."
Private Sub ValueErrorHandler(ByVal sender As Object, ByVal e As EventArgs)
Dim procTxt As Telerik.Reporting.Processing.HtmlTextBox = DirectCast(sender, Telerik.Reporting.Processing.HtmlTextBox)
Try
procTxt.Value = invalidXhtml
Catch generatedExceptionName As Exception
procTxt.Value = defaultXhtml
End Try
End Sub