|
Creating a DotNetNuke module Topic updated 31-5-2007 |
|
You can use GenWise to create DotNetNuke Modules. There is no template specifically targeted at the generation of DotNetNuke Modules, but GenWise can create Web User Controls, which can be enhanced to become DotNetNuke Modules. The steps involved are described in this topic. A template specific to the generation of DotNetNuke Modules is on the GenWise feature wishlist. BO Layer project The module creation steps provided here are based on the assumption that we will use a BO Layer generated by GenWise, so we'll use NHibernate instead of DotNetNuke's DataProvider pattern which relies on stored procedures for all data access. The use of our own BO Layer gives us the freedom to choose whether the data used by the DotNetNuke Module is stored in the same database that DotNetNuke uses, or a different one. If your DotNetNuke Module will use tables from the DotNetNuke database, be selective which tables you add to your BO Layer project. There are many tables in the DotNetNuke databases, but the majority of them you probably won't need. Your BO Layer will become unnecessarily big if you import the whole lot. If you need to filter data with the user's identity or the ModuleId you can retrieve these values from the API that DotNetNuke makes available to modules.
ASP.NET project settings Add a reference to DotNetNuke.dll To add a reference to your project right-click the ASP.NET project item in the Project Explorer and choose References. In the References page click the Add Reference button at the bottom. Turn the Generated and CopyLocal options off.
Page settings Set the following options on page items to turn them into DotNetNuke modules:
Add using directives for referenced DotNetNuke namespaces at the top of the page source. Open the Source Editor for the page, switch to the ascx.cs view and go to the first User Codeblock, add these lines: using DotNetNuke; using DotNetNuke.Entities.Modules; using DotNetNuke.Entities.Modules.Actions;
DotNetNuke project configuration The ASP.NET project templates are configured to generate a standalone website. To integrate the generated output into your DotNetNuke project different parts of it must be copied to different locations in the DotNetNuke website.
It's assumed here that you move the files to these locations manually, and then also add the Module Definition in DotNetNuke manually. This can be done using the DotNetNuke host account. Alternatively you might want to create an installable package for DotNetNuke. For information about these tasks refer to the DotNetNuke documentation. In the Web.config file register the subdirectory of App_Code where we place the C# code files from the ASP.NET output directory from our GenWise project. We do this by adding it to the codeSubDirectories node under the compilation node: <compilation (...)> (...) <codeSubDirectories> (...) <add directoryName="MyModule" /> </codeSubDirectories> </compilation>
Substitute MyModule with the real name you used for the subdirectory under DotNetNuke's App_Code directory.
Copying the theme directory to your module directory under the DesktopModules directory as indicated above is obviously just a quick fix. This makes stylesheet and image references in our generated DotNetNuke module work. By default DotNetNuke uses a skinning technique of its own, not the App_Themes special folder with skin files. Resolving these differences is beyond the scope of this topic.
Adding navigation between controls One DotNetNuke module may consist of several controls. The control to be loaded can be specified by using the ctl request parameter in the http query string. Using DotNetNuke's url rewriter an url that loads a specific control from your module will look something like this: http://<base url>/<pagename>/tabid/<tabid>/ctl/<controlkey>/mid/<moduleid>/Default.aspx The assignment of controlkeys to different controls can be set manually from the Module Definitions page if you are logged on as host. To make the View action work so that we navigate from a Browse to a Form we need to change the behaviour of Browse1_GetFormURL_View(). We want this method to provide our GridView with urls that work within the DotNetNuke environment. We can do this by adding some code as shown below.
protected string Browse1_GetFormURL_View(MyBrowseObj pMyBrowseObj) { if (pMyBrowseObj == null) throw new ArgumentNullException("pMyBrowseObj"); string _url = "MyBrowseObjForm.aspx?Action=View"; _url += "&mybrowseobjID=" + HttpUtility.UrlEncodeUnicode(pMyBrowseObj.mybrowseobjID.ToString());
_url = DotNetNuke.Common.Globals.NavigateURL(this.TabId, "form", new string[] { "mid", this.ModuleId.ToString() }); _url += "?Action=view"; _url += "&mybrowseojbID=" + HttpUtility.UrlEncodeUnicode(pMyBrowseObj.mybrowseobjID.ToString());
return _url; }
In the code above we use DotNetNuke's global NavigateUrl() function to get the url we need and use this to override the value of _url that is returned. The second parameter specifies the controlkey that we define via the Module Definitions page.
|