Home » DotNetNuke - Module Development » DotNetNuke Modules – Inter Module Communication

DotNetNuke Modules – Inter Module Communication

G03A0039 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: an style=”color: blue;”>using DotNetNuke.Entities.Modules.Communications;

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 :

To implement the interface that will allow a module to listen for the event, implement the IModuleListener interface:

partial class ViewDMBSample :

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:
PropertyDescriptionSenderThis is a string value that allows you to specify who sent the message.TargetThis is a string value that allows you to specify who you want to pick up the message.TextThis is text that allows you to attach free form text to the payload.TypeAnother string that you can use however you want, but it is best used to specify the type of the Value property.ValueAn 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

Related Post

  • DotNetNuke Modules – Creating Base ModulesDotNetNuke Modules – Creating Base Modules Now that we have DotNetNuke installed into Visual Studio we can go ahead and create our first modules. Actually, creating the modules is pretty simple. But it is even easier to do it […]
  • DotNetNuke Modules – Finding The Page a Module is OnDotNetNuke Modules – Finding The Page a Module is On Last week we talked a bit about Inter Module Communication, the ability of one module to notify another module on the page that something needs to happen without requiring a post back.  […]
  • Changing an Existing DNN ModuleChanging an Existing DNN Module Got this question this morning from the “Ask A Question” form. “How do I make a change in an existing DotNetNuke module?  I want to add new fields to the feedback form.” I’m […]
  • DotNetNuke Modules – Install DNN into VS 2008DotNetNuke Modules – Install DNN into VS 2008 Today, we will install DotNetNuke into Visual Studio so that we can create our first module. So fire up Visual Studio, and let's get going.I'll be using Visual Studio 2008 to walk […]
  • DotNetNuke – Make Your Module SearchableDotNetNuke – Make Your Module Searchable So far, you know everything you need to know to get a basic module up and running. There are a few items we still need to cover regarding the configuration of your module so that it can […]

About Dave Bush

Dave Bush is a Full Stack ASP.NET developer focusing on ASP.NET, C#, Node.js, JavaScript, HTML, CSS, BootStrap, and Angular.JS.Does your team need additional help in any of the above? Contact Dave today.

  • Tom

    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?

  • Dave

    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.

  • Shey

    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?

  • Dave

    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.