Wednesday, April 29, 2009

Everything I know about SSRS Reports and ReportViewer

Today, I was struggling with the ReportViewer control.

Actually, that's not entirely true. I've been struggling with it for some time.

We were wrapping the control in our own to paint parameters because the original implementation was so buggy. It would die if you tried to render it inside of a DIV that was not absolutely positioned and then if you tried any of the numerous workarounds, it would offset drop-downs and behave horribly.

The first solution I found was straightforward. There is a new control, and many of the bugs have been fixed. It's a beauty!

Grab the Microsoft Report Viewer Redistributable 2008, uninstall the old one, and get this one in as quickly as possible. You'll love it. Be sure to update your references to point to 9.0.x version instead of 8.0.x version. This can be in references, web.config, and the register assembly directives in your pages.

If you don't like the vertical scrollbar, set asnychronous rendering to false. It will postback when the user navigates, but it will also allow the control to size the page appropriately for the browser window.

Finally, if you get the quirky Microsoft JScript runtime error: 'this._postBackSettings.async' is null or not an object in your browser when using it, don't despair. Fire up the code behind for the page the control lives on, and add this code snippet to disable partial rendering in the ScriptManager:

protected void Page_Init(object sender, EventArgs e)
{
    ScriptManager sm = ScriptManager.GetCurrent(this); 
    if (sm != null)
    {
        sm.EnablePartialRendering = false;
    }
}

(It's important to do it in Init, so it can go into your control if you are wrapping the control, but then you must make sure that dynamic controls are injected in Init or you'll miss the boat).

There we go. Now you know everything that I do about report viewer.