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

How to handle errors in silverlight viewer

1 Answer 156 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 02 Apr 2012, 08:02 PM
This seems to be something that would be fairly commonly needed, but I haven't been able to find out how to do it. So apologies if this is covered in the documentation somewhere. 

I need to catch the errors that show up and show some custom error text that is more user-friendly. For a timeout, I want to show something like "Report generation timed out, please try again.". What I don't want to show an end user is a full stack trace that shows up by default. So how can I capture the error, and change what gets displayed? 

I have actually seen two different time out messages. The most common one (attached: silverlighttelerikerrordisplay.png), and one I've only seen once (second attachment: silverlightteleriktimeout2.png). If I could get it to do this simpler, second option all the time, I could live with that. 

Also, I've tried dealing with the error message in the RenderAndCacheComplete event handler. However, the best I can do is put another control on the screen that has some text in it, which ends up looking like the third attachment (customerrorbox.png). If I could find a way to clear the content of the built-in error page, I could probably live with this option too. 

Any other ideas, or ways to improve the two potential options above?

TIA,
-David

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 04 Apr 2012, 03:00 PM
Hi David,

Currently we don't provide options for customizing the Silverlight report viewer errors. Still we will have in mind your suggestion for future report versions when working on report error handling improvements. In general the errors displayed in the report are for the developer to see and the end user should not get any errors when running your application.
You can check for errors as shown in the following code snippet. However altering the Error property will not update the report viewer error message and you have to use custom mechanisms for alerting your application users with customized messages.

Copy Code
public partial class MainPage : UserControl
{
    ReportViewerModel viewerModel;
    ReportViewerModel ViewerModel
    {
        get
        {
 
            if (viewerModel == null && VisualTreeHelper.GetChildrenCount(this.ReportViewer1) > 0)
            {
                var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(this.ReportViewer1, 0);
                viewerModel = (ReportViewerModel)layoutRoot.DataContext;
            }
            return viewerModel;
        }
    }
 
    public MainPage()
    {
        InitializeComponent();
        this.ReportViewer1.RenderBegin += this.ReportViewer1_RenderBegin;
    }
 
    void ReportViewer1_RenderBegin(object sender, RenderBeginEventArgs args)
    {
        this.ReportViewer1.RenderBegin -= this.ReportViewer1_RenderBegin;
        this.ViewerModel.PropertyChanged += this.ViewerModel_PropertyChanged;
    }
 
    void ViewerModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "State"
            && this.ViewerModel.State == ReportViewerStates.ViewerError)
        {
            var error = this.ViewerModel.Error;
        }
    }
}

Regards,
Steve
the Telerik team
NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or