Geeks With Blogs
Evil Dev's Blog Plots, Schemes, and Plans to take over the Devleoper world.... Mu hahahaha

So, today I was working with the ASP.NET Report Viewer Control. If you don't know what that is, it's an ASP.NET control that comes with .NET, and what it does is allows you to display a SSRS Report on your website. True to ASP.NET, it seems very simple at first, drag, drop, set parameters... and then of course, there's the fallbacks on the things it cannot do.

A major thing to me, when I'm developing a website, especially recently, is performance. I hate going to a website, and waiting more than 3-5 seconds for a page to be rendered and useable on my screen. So, when I build a webpage, it simply won't do to put my users through what I myself can't tolerate. (Plus, I get less frustrated when debuggin that way).

Well, turns out the way this control works, it's kind of neat, there's a little property to allow it to do what it needs to do asynchronously, so it renders the control quickly, and it then goes and gets the report. And I thought, hey, that's neat. But here's the thing, the application I am working on, is not an Asp.Net powered app, it's actually an XSL Transform powered application. For now, I simply do not know if it's worth it/possible to get a report from reporting services rendered to a webpage in using an XSL Transform. It definately is not a built-in "Feature".

So, the solution I came up with was to create one single ASP.NET Page, to be the master report viewer page. The one ring to display them all if you will. Keep in mind, I'm not really a front end guy, so my experience with Asp.NET is somewhat limited. I go ahead, add the Aspx page to my project, do the necessary configuration/handler building/setup stuff required to make it work.

My next step is to add the report viewer control to the page. Easy. Drag, Drop, done. I then proceed to the code behind to do a little "grab report name/report parameters out of the query string" code, and pass them to the control. Again, easy. Try it out, it works. Don't like the fact that when I resize the page, it doesn't resize the control, break-out some mad javascript goodness, and ok, vola, it resizes with the page.

INTERMISSION RANT: Why is the "Auto-resize control to parent" feature non-existant in like ALL built-in Asp.net Controls??
END RANT

OK, so now we seem to have all that working. Great. Fire it up, sure enough it works, the report renders to the page. I'm done right?

Not quite. Turns out, one of my reports, is a Summary Report, that links to detail report. Linking between reports, breaks the whole process.

Workaround? Seems to me the only work around is to change how the Summary Report Navigates to the detailed report, but changing the navigation property of said report items in the report, so instead of linking to a report, I link to the report viewer page I just created, passing in the required parameters into the query string.

Well, works like a charm, but breaks the whole "Link To Report" feature in my reports, and breaks the back button functionality of the report itself. Also, true to Asp.Net Style, the whole page does a post back, and then re-renders itself with the new report.

So now, I'm digging through articles, reverse engineering the control etc, to see if there's some cool client side event I can call to trigger the report to load the detailed report client side, so my page doesn't have to go through it's entire lifecycle to simply reload part of the page.

END OF ARTICLE RANT: Also, I'm not a huge fan of the way the report viewer works. It essentially, renders an IFRAME containing the report, and inside the IFRAME it's doing a bunch of Frameset stuff, that's really annoying. It's really bad HTML output to the screen, and doing way more garbage than it should, but who am I to judge right?
END OF END OF ARTICLE RANT

Posted on Wednesday, September 9, 2009 8:12 PM SQL Server Reporting Services , .NET Development | Back to top


Comments on this post: ASP.NET Report Viewer Control

# re: ASP.NET Report Viewer Control
Requesting Gravatar...
I love the simplicity of creating reports for the Report Viewer Control. Like you I have also used some JavaScript magic to get it to do things like resize with the page and added client side controls to hide/unhide the parameter section.

One thing I'd like to mention is that you can use the report viewer control to render directly to a PDF or Excel file and then stream that out to the client. There are a bunch of posts on how to do this but here is a link to the first one that came up on Google: http://weblogs.asp.net/kyleholder/archive/2008/03/05/render-the-contents-of-a-reportviewer-control-directly-to-pdf.aspx

I've done some AJAX goodness in the past that sends JSON data back to the server, used that data in a .rdlc report and then streamed it back to the client. All without a single post back. If you would like I could try to find some time to post an article about that.

If you need the actual control on the front end and streaming the report as a PDF or Excel file won't do you could set up a nice work around utilizing an IFRAME. First, create a seperate page that just contains the report viewer control and some hidden fields to store the report parameters if there are any. Next, add an IFRAME to the pages you want to display the report and point to the page with the report viewer control on it. Finally, set up some JavaScript on both pages to pass parameters back and forth, resize the report viewer control and IFRAME as wanted, and some script to submit the report page.

It works like a charm if you get it all set up properly. It gives the user that AJAXy feeling since the only thing being refreshed is the report. Again, I probably should post an article on this but need to find the time.
Left by kerv on Sep 10, 2009 10:26 AM

# re: ASP.NET Report Viewer Control
Requesting Gravatar...
Why not render the report directly using the ServerReport.Render() method, which will give you back HTML/XML/PDF/whatever, and then you can just stick that in a div on your page? You would lose some of the ReportViewer functionality like searching, export button, paging, etc. But depending on what your report is that might not be too big of a deal.
Left by Jason Coyne on Sep 10, 2009 11:24 AM

# re: ASP.NET Report Viewer Control
Requesting Gravatar...
@kerv Thanks for the suggestions! And yes, I've already looked at the streaming the PDF and Excel File directly, but that's not going to work for this project, as the online reports are the reason we are using reporting services. I love/hate the simplicity of creating the reports, in some instances it's gods gift to developers it's so quick and easy, and in other ways it's a real pain to do stuff like striping row colors lol. I already thought about the IFrame method, I just feel dirty when I do stuff like that, IFrames, inside of IFrames, containing framesets... just seems so wrong to me. But if all else fails that's probably the route I'm going to go.

@Jason, That's definately something I'm going to investigate, I wasn't aware you could get back the HTML of the report. As the application is written with an xsl framework, it may be possible to utilize this method to grab the report HTML, and keep the framework/code consistant across the app. As far as the paging/export options, I believe there are methods to simulate those kinds of things yourself, so if nothing else I can probably create my own mock report viewer control, which may actually be the only way to get it to do exactly what I want it to.

In all, thank you both very much for your suggestions, as SSRS is still really new to our company, we don't have any experts in using it, so I definately appreciate the suggestions/feedback.
Left by Mitchell Lee on Sep 10, 2009 11:42 PM

# re: ASP.NET Report Viewer Control
Requesting Gravatar...
Do you have the code you could post someplace for an example? This is exactly what Im trying to do myself with an IFrame?
Left by Denise on Sep 23, 2009 12:59 PM

# re: ASP.NET Report Viewer Control
Requesting Gravatar...
@Denise, yes, there is some explanation/example code on my follow-up post:

http://blog.theevillittledeveloper.net/archive/2009/09/16/mitch-vs-asp.net-report-viewer-control-round-two.aspx

I can provide more detail/assistance if you need more information.

Hope that helps!
Left by Mitchell Lee on Sep 23, 2009 1:20 PM

# re: ASP.NET Report Viewer Control
Requesting Gravatar...
You mention using JavaScript to resize the control. Could you send me this code? Thanks
Left by Mike Johnson on Dec 04, 2009 9:35 AM

# re: ASP.NET Report Viewer Control
Requesting Gravatar...
I would love teh code as well. Will you please post or send to me? thanks.
Left by Cindy on Feb 02, 2010 3:54 PM

# re: ASP.NET Report Viewer Control
Requesting Gravatar...
Sorry for the late response, I can't provide the actual code, but essentially I just utilized the prototype javascript library (pretty sure jQuery has something like this too) for it's ViewPort.

Here's a basic example from memory:

document.observe("dom:loaded", function(evt){
resizeControl('<% =ReportViewer.ClientID %>');
}

window.onResize = function(evt,args){
resizeControl('<% =ReportViewer.ClientID %>');
}

resizeControl(element){
$(element).height = document.viewport.height;
$(element).width = document.viewport.width;
}

Hope that helps,
- Mitch
Left by Mitchell Lee on Mar 03, 2010 8:00 PM

Your comment:
 (will show your gravatar)


Copyright © Mitchell Lee | Powered by: GeeksWithBlogs.net | Join free