ASP.NET Wrapper Walkthrough Microsoft ReportViewer9
From Visual WebGui Wiki
Contents |
Overview
Operating the ASP.NET Wrapper to wrap simple ASP.NET controls if fairly easy. As an example here, we will take wrapping of Microsoft's ReportViewer version 9 and wrap it using VB.NET in Visual Studio 2008. There are minor differences between wrapping in C# and VB.NET, but they are minimal.
You should also note, that this walkthough assumes you have the Visual WebGui Professional Studio with the Visual Studio integrations that it includes. For other versions of Visual WebGui, manual steps are required which are out of the scope of this walkthrough.
Creating a library project
- Create a new project of type Visual WebGui Library, name it ReportViewer9Wrapper
- Delete the automatically created UserControl1 from the new project
- Add references to Microsoft.ReportViewer.WebForms and make sure it is version 9.
- Add references to System.Web
At this point, the wrapper will recognize the ReportViewer control for wrapping. Without adding the correct references, it will not.
Wrapping the control
- Right-click on your project, select Add and then ASP.NET Control Wrapper.
- In the list of controls, select ReportViewer, and again make sure it is of version 9
- Name the Wrapped control ReportViewer9
Manually fix autogenerated code minor errors
At this point you have a wrapped control, but you must do minor fixes by editing the ReportViewer9.designer.vb file. Right-click that file, and View Source.
- The class is now declared as "Partial class", which means it is a "Friend" class (in VB.NET terms) and it will not be possible to use that class outside of the Library project. Our purpose is of course to use it outside that project, so we must change the "Partial class" declaration to "Partial Public Class".
- In the autogenerated code, there is a declaration for "Public Sub Reset()". You will get some errors with calls to that proc. Simply rename it by change the declaration to "Public Sub ResetHostedViewer()".
- You will get error for "Public Sub Dispose()", which you simply fix by making it overload the base class's sub by changing the code to "Public OverLoads Sub Dispose()"
Preventing display issues in some browsers
Some browsers, notably FireFox 3, has problems displaying wrapped ReportViewer controls. To minimize the risk of those issues, we can use the fix presented in the How-To article and add the following code to the class.
Protected Overrides ReadOnly Property IsFixedSize() As Boolean Get Return True End Get End Property
Adding the wrapped control to your Form
At this point, you have a fully working wrapped control.
- Create a new project of type Visual WebGui Application. For this walkthrough, name your project ReportViewer9WrapperTest.
- Add reference to your newly created project, ReportViewer9Wrapper.DLL
- Add reference to all the usual Gizmox DLL's, as well as other DLL's needed for your application.
Register your control
To be able to use the control in your Visual WebGui application, you need to register your control in Web.Config. The easiest way to do that is to use the Projessional Studio integration tabs.
- Right click on your application project and select Properties
- Select the Reistration tab
- Go to the Controls grid in the middle, and press the insert button on right
- Locate your ReportViewer9 control and make sure it is checked.
- Save and close the integration screen.
Other specific changes in web.config
Special requirements are made on settings in web.config on behalf of the Microsoft.ReportViewer version 9 control. You need to manually add the following into HttpHandlers secion of your web.config.
<add verb="*" path="Reserved.ReportViewerWebControl.axd" type = "Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Please note that the code above should appear on a single line. Linebreaks here are for readability.
The control is ready
At this point, the control is ready to be used on a form.
You should save everything, increment the private version of your project and recompile before you continue to next step.
Adding the control to your form
Open Form1 in designer, and look at the Toolbox. If everything has been done correctly, you should now see ReportViewer9 control appearing in your Toolbox.
To add it to your form, simply grap it, drag it over your form and drop it there.
You now have ao form with a ReportViewer control on it.
Using the ReportViewer control
The details on how to use the ReportViewer control to create reports are out of the scope of this article.
You can download the sample code and take a look at the two samples presented there. One using a local report datasource, and the other using the NorthWind example database.
References
