DotNetNuke Modules – Inter Module Communication
If you spend any time at all writing DotNetNuke modules, you will eventually run into a situation where you need one module to communicate with another. There are several methods of achieving this communication, but there is one DotNetNuke-sanctioned way that looks a bit more confusing, at first glance, than it really is. In fact, once you see how simple it is, you’ll wonder why you didn’t use it before.
Inter Module Communication (IMC) uses a basic event-based mechanism. This means that you will have one module that sends the event and another module that receives the event. Since the event is the same event, any module listening for the event will hear all of the events that fire on the page, not just the event you will fire. Therefore, you’ll need to make sure that the event you fire has enough unique information in it that your listener can determine that it is an event it should pay attention to.
To implement IMC on your module you’ll need to add the following using statement to the top of both your listening module and the module that will be firing the event:
This will allow us to add the appropriate interfaces to the module class.
To implement the interface that will allow us to fire the event, implement the IModuleCommunicator interface:
partial class ViewDMBSample : PortalModuleBase, IActionable, IModuleCommunicator {
To implement the interface that will allow a module to listen for the event, implement the IModuleListener interface:
partial class ViewDMBSample : PortalModuleBase, IActionable, IModuleListener {
To fire the event from your IModuleCommunicator module, you'll need to call ModuleCommunication(this, ModuleCommunicationEventArgs).
The first parameter will pass a pointer to the module object with the event. You could use this to pull specific information from it using properties or methods you may have implemented on the module. Keep in mind that if you want to use properties or methods from the module, it is best to implement an interface that you can apply to the module so that when the listener gets the object, you can cast the sender to the interface rather than trying to cast it to the ASCX object, which doesn't always work.
The second property is a DotNetNuke object that you will create and stuff with the following properties:
| Property | Description |
| Sender | This is a string value that allows you to specify who sent the message. |
| Target | This is a string value that allows you to specify who you want to pick up the message. |
| Text | This is text that allows you to attach free form text to the payload. |
| Type | Another string that you can use however you want, but it is best used to specify the type of the Value property. |
| Value | An object that lets you pass whatever you want. |
Once you have fired the message, the listener will need to pick it up. You do this by implementing the OnModuleCommunication method.
<
span style="color: blue;">public void OnModuleCommunication(
object s, ModuleCommunicationEventArgs e)
{
// Do something with the message here.
}
Other places talking about IMC:
DotNetNuke Inter-Module Communication or: How Your Modules Can Get ... - If you have been writing your own DotNetNuke modules for any amount of time you have probably run across the concept of Inter-Module Communication (IMC for short). IMC particularly refers to the facility that the DotNetNuke framework ...
Inter Module Communication in DNN using C# - Well, this post I will share with you my finding about the DNN IMC, something like you want to pass 1 or more values from one module to another module, imagine you created 2 modules, one is search module another one is result list ...
Other post in DotNetNuke - Module Development
- Creating DotNetNuke Modules - May 20th, 2008
- Creating DNN Modules - The Tools - May 22nd, 2008
- DotNetNuke Modules - Foundational Concepts - May 26th, 2008
- DotNetNuke Modules - Install DNN into VS 2008 - May 27th, 2008
- DotNetNuke Modules - Creating Base Modules - May 28th, 2008
- DotNetNuke Modules - Registering Your Module - May 29th, 2008
- DotNetNuke Modules - Where Stuff Shows Up - June 3rd, 2008
- DotNetNuke Modules - Benefits of Architecture - June 4th, 2008
- DotNetNuke Modules - Anatomy of the View - June 9th, 2008
- DotNetNuke Modules - Adding Actions - June 11th, 2008
- DotNetNuke Modules - DNN Controls - Label - June 18th, 2008
- DotNetNuke - Internationalization - June 25th, 2008
- DotNetNuke Modules - Internationalization (part 2) - June 30th, 2008
- DotNetNuke Modules - Labels w/ no Help - July 9th, 2008
- DotNetNuke Modules - LinkButtons - July 14th, 2008
- DotNetNuke Modules - Collapsible Panels - July 16th, 2008
- DotNetNuke - The Data Layer - Installing CodeSmith - July 22nd, 2008
- DotNetNuke - Modules - Creating The Tables - July 24th, 2008
- DotNetNuke - Modules - Creating Stored Procs - July 29th, 2008
- DotNetNuke - Modules - Portal Specific Modules - July 31st, 2008
- DotNetNuke Modules - Data Access Layer - August 5th, 2008
- DotNetNuke Modules - Data Access Layer - August 7th, 2008
- DotNetNuke - Data Access Layer Alternative - August 12th, 2008
- DotNetNuke - Modules - Linking within the module - August 14th, 2008
- DotNetNuke - Make Your Module Searchable - August 19th, 2008
- DotNetNuke Modules - Making Content Portable - August 25th, 2008
- DotNetNuke Modules - Exceptions the DNN Way - September 2nd, 2008
- DotNetNuke Modules - PortalModuleBase - September 4th, 2008
- DotNetNuke Modules - Inter Module Communication - September 9th, 2008
- DotNetNuke Modules - Finding The Page a Module is On - September 15th, 2008
- DotNetNuke Modules - Caching - September 17th, 2008
- DotNetNuke Modules - Module Settings - September 22nd, 2008
- DotNetNuke Modules - Retrieving Settings - September 24th, 2008
- DotNetNuke Modules - Advanced Architecture - October 20th, 2008
- DotNetNuke Modules - Creating the PA - October 30th, 2008
- DotNetNuke Modules - Automating the PA - November 5th, 2008
- DotNetNuke - FileUploadControl Danger! - February 26th, 2009
- DotNetNuke SecurityException AspnetHostingPermission - October 14th, 2009
Other Related Items:
Wanderin'Includes 6 bonus tracks.
Beginner's ASP.NET in VB.NET 2003 on DVDASP.NET (VB.NET) 2003 represents an important technology for building enterprise level web applications. Learn the basics of ASP.NET development as yo... Read More >
ICM275 Carrier HH84AA021 Fan Blower Control BoardICM 275 Fan Blower Control SpecificationsInputVoltage:18-30 VAC
Frequency: 50/60 Hz
OutputContact Ratings:
20 amps @ 240 VAC on hig... Read More >










Nice post. Would you recommend using IMC over passing parameters through a query string to use one module as a kind of dashboard to control an other?
It would depend on what you were trying to do. IMC is used when you need to have one module on a page “talk” to another module on a page during a single round trip.
You can’t do that with a query string because you’d need to have at least two round trips to the server. The first to figure out what the query string was suppose to be and the second to have the second module answer it.
Really enjoy this site with it’s straightforward, no-holds-barred approach to real-world development.
Dave: “you can cast the sender to the interface rather than trying to cast it to the ASCX object, which doesn’t always work.”
Please could you provide an example(s) of when this wouldn’t work, and why?
The problem is that sometimes the code will not compile even though it is correct. This can happen more often if you change the public methods and properties.
There isn’t any code I can give you to replicate the problem because sometimes it will compile fine and other times it doesn’t.