Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

IModuleControl

Return to previous page

  • 4/7/2015
  • 5991 Views

Comments

5991 Views

IModuleControl

Last updated long time ago

Comments

Common

(Enter the content of this article below)

Advanced

 
The IModuleControl interface (DotNetNuke.UI.Modules.IModuleControl) which was introduced in DotNetNuke framework version 5.00.00 defines five member properties which any module control must implement.

Namespace DotNetNuke.UI.Modules

Public Interface IModuleControl
ReadOnly Property Control() As Control
ReadOnly Property ControlPath() As String
ReadOnly Property ControlName() As String
Property LocalResourceFile() As String
ReadOnly Property ModuleContext() As ModuleInstanceContext
End Interface
End Namespace

In most cases, your module controls will inherit either from DotNetNuke.Entities.Modules.PortalModuleBase or in the case of modules which manage DotNetNuke users from DotNetNuke.Entities.Modules.UserModuleBase which itself inherits from PortalModuleBase. PortalModuleBase implements IModuleControl along with many other helpful properties and methods necessary for module development. Therefore, except in a few special cases, you will not be responsible for implementing IModuleControl.

Let's look at the four read only properties and one read/write property defined by the IModuleControl interface:

Control - Returns a reference of type System.Web.UI.Control to the ASP.Net control represented by your module control. Most often this will be a System.Web.UI.UserControl but it could also be a custom server control. The default implementation in PortalModuleBase imply returns the reference Me (for VB.Net) or this (for C#.Net)

ControlPath - Returns as a System.String the web application root relative path to the module control, for example: DesktopModules/Feedback/. Note that in the default implementation in PortalModuleBase, the ControlPath will always end with a forward slash.

ControlName - Returns as a System.String the simple name of the module control (NOT the full namespace-qualified name), for example: Feedback

LocalResourceFile - Returns as a System.String or takes a System.String parameter to set the web application root relative path to the localization resource file (.resx) associated with the control. Continuing the example from the DotNetNuke Feedback module, the LocalResourceFile property would be set by core code when the module control is injected into the page to "DesktopModules/Feedback/App_LocalResources/Feedback.ascx.resx". The default implementation of the getter for the LocalResourceFile property in PortalModuleBase is an interesting one which deserves a bit of explanation as the name of the LocalResourceFile is not what you might expect it to be when the module control is a child of another control:

Public Property LocalResourceFile() As String Implements IModuleControl.LocalResourceFile

Get
Dim fileRoot As String

If String.IsNullOrEmpty(_localResourceFile) Then
fileRoot = Path.Combine(Me.ControlPath, _
Services.Localization.Localization.LocalResourceDirectory & "/" & Me.ID)
Else
fileRoot = _localResourceFile
End If
Return fileRoot
End Get
Set(ByVal Value As String)
_localResourceFile = Value
End Set
End Property

In the getter above, the static, read only property Services.Localization.Localization.LocalResourceDirectory always returns "App_LocalResources".

Let's say that your module control (Feedback.ascx) loads (either in its markup or in code) a child module control having a relative filepath of "DesktopModules/Feedback/Controls/Ratings.ascx" and an ID="ctlRatings1". Unless you explicitly set the LocalResourceFile property of the child control (often to the LocalResourceProperty of the parent control), the default LocalResourceFile for the child control will NOT be "DesktopModules/Feedback/Controls/App_LocalResources/Ratings.ascx.resx" or even "DesktopModules/Feedback/App_LocalResources/Feedback.ascx.resx" as you might expect but rather "DesktopModules/Feedback/Controls/AppLocalResources/ctlRatings1.ascx.resx". Note how the child control ID "ctlRatings1" becomes the name of the resource file.

ModuleContext - The ModuleContext property returns an object of type DotNetNuke.UI.Modules.ModuleInstanceContext which exposes many of the module instance's important properties such as TabId and TabModuleId as well as PortalID, PortalSettings, the Settings hash, and Configuration of type DotNetNuke.Entities.Modules.ModuleInfo which contains or exposes all the familiar module entity properties and provides methods for constructing the module's action menu and building urls to other module controls.

The IModuleControl interface is most often used in core code when injecting a module into the page, when localizing a module control's various child controls, when setting and getting a module control's contents and metadata from the cache, and in several host/administrative modules such as Host-->Extensions which manipulate a module's metadata.

IModuleControl also forms the base interface for the ISettingsControl interface also described in this Wiki.

Increasingly we will be seeing new modules built using the WebForms MVP pattern. Typically in the MVP pattern, your module controls will inherit from the class DotNetNuke.Web.Mvp.ModuleView (Of TModel) which inherits from DotNetNuke.Web.Mvp.ModuleViewBase which inherits from DotNetNuke.UI.Modules.ModuleUserControlBase which implements IModuleControl in an identical fashion as PortalModuleBase. This is good news as all of our usual module control properties will be available for use in our view controls AND our presenters into which the view is passed at the time the presenter is constructed. ModuleUserControlBase is also becoming used more frequently than PortalModuleBase for new administrative module controls.

Example Code (C#)

Class Declaration


public class ModuleUserControlBase : UserControl, IModuleControl

Implementation


private string _localResourceFile;
private ModuleInstanceContext _moduleContext;

public Control Control {
get { return this; }
}

public string ControlPath {
get { return TemplateSourceDirectory + "/"; }
}

public string ControlName {
get { return GetType().Name.Replace("_", "."); }
}

public string LocalResourceFile {
get {
string fileRoot;
if (string.IsNullOrEmpty(_localResourceFile)) {
fileRoot = Path.Combine(this.ControlPath, Services.Localization.Localization.LocalResourceDirectory + "/" + this.ID);
} else {
fileRoot = _localResourceFile;
}
return fileRoot;
}
set { _localResourceFile= value; }
}

public ModuleInstanceContext ModuleContext {
get {
if (_moduleContext == null) {
_moduleContext = new ModuleInstanceContext(this);
}
return _moduleContext;
}
}


Contents
No sections defined
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out