Smart Tasks
Visual Studio gives you a tool that makes programming applications easier. This tool is called a Smart Tasks panel. When you add a control to a form, a little arrow appears in the top-right corner of the control. Clicking on it triggers a panel to appear with a short menu list of common tasks and properties. The items on this panel are typically things that you will most frequently need. There can also be shortcuts that make it easy to perform certain operations. Using the Smart Task panel in a Windows application produces auto-generated code in a hidden class file called a partial class. When doing it in a web application, it produces auto-generated XML in the ASPX page. Using the Smart Tasks panel is the quickest way to integrate a report into your application because it doesn’t require writing any code. This rapidly speeds up development time.
Although the Windows version is very similar to the web version, there are some differences. In fact, you might recall from Chapter 1 that we used the Smart Tasks panel to create both a Windows app and Web form. To make it easier on you, I copied the figures from Chapter 1 here. Figure 3-1 is the Smart Tasks panel on a Windows form and Figure 3-2 shows it on a web form.
Figure 3-1. Smart Tasks panel on a Windows form.
Figure 3-2. Smart Tasks panel on a web form.
You can see that the two panels are very similar, but the web version has a few more options. The first option(s) on each panel lets you either attach an existing report to the viewer control or create a new report from scratch. For some reason, the Windows version uses two links to do this and the web version uses a drop-down list where you choose the option you want from the list.
Upon completion, the web designer automatically creates a CrystalReportSource control and places it on the web form. The CrystalReportSource control enables the tag based application development model, which makes it possible to open the report using XML embedded into the ASPX page. If you are working with a Windows application, you can have the viewer’s ReportSource property reference the embedded report class directly or point to the physical report file located on your computer.
Upon completion of selecting/creating the report, both viewer controls will update themselves to show you a preview of the report. Being able to preview a report in design mode is a feature that wasn’t available in previous versions of ASP.NET and was a very popular feature request.
The next set of options lets you turn certain viewer features on and off. For example, you can show/hide the toolbar, group tree, status bar and report view. The option to display the status bar is only available on the Windows version because the web report viewer doesn’t have a status bar. The option to enable the report view lets you show/hide the report preview in design mode. Although you can preview a report in design mode in both Windows and web forms, the option to disable that feature is only available on the web version of the panel.
The web Smart Tasks panel gives you the option to prompt the user for the login credentials and setting parameter values. In previous versions of ASP.NET, Crystal Reports would crash the web page if you didn’t properly supply the user credentials and report parameters via the ReportDocument class prior to showing the report. New for Visual Studio .NET 2005 is that there is a pre-defined web page that is shown to the user if either of those items weren’t set correctly. The Smart Tasks panel gives you the option to disable this new feature if you wish.
The last checkbox on the web Smart Task panel lets you persist parameter values between page refreshes. When this is enabled, the user is not prompted to enter the parameter values a second time because they are cached and reused. If this option is disabled, the parameter choices are discarded upon report refresh and you will have to write code to manually populate them via the ReportDocument object model.