Are you building modules in DotnetNuke?
Is one module depends on another module?
Want to exchange data between modules?
Here we can discuss how to set up Inter Module Communication in DotnetNuke. In DNN, with the help of IModuleCommunicator and IModuleListener interfaces we can setup the communication between the modules.
Here I would like to present all the required steps to setup the communication between modules. Before we start discuss on this, let’s understand who is communicator and who is listener.
Communicator, is a module which establish the communication with other module. In other words, a module which sends the information to other module.
Listener, is a module which gets the connection from other module. In other words, a module which receives the information from other module.
Now I will practically show you how to configure the communication between DNN modules. In my example Module X will act as Communicator and Module Y will act as Listener.
Module X, in which I am showing all the available users from the current DNN portal in a DropDownList control. And when the user selected from the DropDownList, I am sending the selected user name to Module Y.
Module Y, in which simply I am receiving the selected user name from Module X and showing it in a Label control as message.
Communicator Module (Module X):
The UI page (view.ascx) of communicator module has a dropdownlist to populate all the user names from the portal:
<div> |
In order to make this Module X as communicator module, in code behind (view.ascx.cs) page we need to implement the IModuleCommunicator interface. ModuleCommunicationEventArgs class would be used to share the information with other modules.
using DotNetNuke.Entities.Modules.Communications; public partial class View : PortalModuleBase, IActionable, IModuleCommunicator private void Page_Load(object sender, System.EventArgs e) protected void ddlUsers_SelectedIndexChanged(object sender, EventArgs e) |
In the above code, selected user name is passing as parameter to ModuleCommunicationEventArgs class constructor and the object of it is passing a parameter to event handler.
Listener Module (Module Y):
The UI page (view.ascx) of Listener module has a simple UI with only one label control used to display the user name which is received from Communicator module (Module X).
<div> |
In order to receive the information from communicator module, each listener module should implement IModuleListener interface which needs to implement OnModuleCommunication method. With the help of below code you can make the module as a listener module.
using DotNetNuke.Entities.Modules.Communications; public partial class View : PortalModuleBase, IActionable, IModuleListener |
When you call the module communication event handler on Module X, all the listener modules on the page will be activated and fires the OnModuleCommunication method in listener modules
You can make the communicator module as a listener module to other communicator module and also a communicator module can have multiple listener modules.
Limitation: You can setup the communication between modules only if the modules are located on the same page. It is not possible to make the communication between Module X which is on Page1.aspx and Module Y which is on Page2.aspx
Hope this helps..!