X
18May

How to setup Module to Module communication in DotnetNuke

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.

Module to Module Communication

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>
   <
asp:DropDownList ID="ddlUsers" runat="server" AutoPostBack="true"      OnSelectedIndexChanged="ddlUsers_SelectedIndexChanged">
   asp:DropDownList>
     <
br />
   <
asp:Label ID="lblMessage" runat="server" Text="">asp:Label>
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
{

   public event ModuleCommunicationEventHandler ModuleCommunication


   private void Page_Load(object sender, System.EventArgs e)
   {
      try
      {
         if (!IsPostBack)
         {
            ArrayList alUsers = UserController.GetUsers(this.PortalId);
            ddlUsers.DataSource = alUsers;
            ddlUsers.DataTextField = "DisplayName";
            ddlUsers.DataValueField = "UserId";
            ddlUsers.DataBind();
         }
      }
      catch (Exception exc)
      {
            Exceptions.ProcessModuleLoadException(this, exc);
      }
  }

  protected void ddlUsers_SelectedIndexChanged(object sender, EventArgs e)
  {
     if (ModuleCommunication != null)
     {
        ModuleCommunicationEventArgs mcArgs = new        ModuleCommunicationEventArgs(this.GetType().ToString(), ddlUsers.SelectedItem.Text,    this.GetType().ToString(), "ModuleY");
        ModuleCommunication(this, mcArgs);
     }
     else
     {
       lblMessage.Text = "Can't communicate with other modules!";
     }
   }
}

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>
   <
asp:Label ID="lblMessage" runat="server" Text="">asp:Label>
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
{
  public void OnModuleCommunication(object s, ModuleCommunicationEventArgs e)
  {
    lblMessage.Text = "Received User Name: " + e.Value;
  }
}

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..!

 

Related

Deploy .NET application on IIS using GitHub actions

In this blog I will be showing how to deploy a .net application on IIS server (self-hosted runner). ...

Read More >

What are Frames? How to handle frames in Selenium WebDriver with C#?

IFrame (FullForm: Inline Frame) is an HTML document that is included in another HTML document and is...

Read More >

What is Synchronization? Handling Synchronization in Selenium WebDriver using C#:

Synchronization meaning: when two or more components involved to perform any action, we expect these...

Read More >

Sending Test reports by Email using Office 365, Gmail

Wouldn’t it be great if Test Report are sent automatically across team as soon the Test Execut...

Read More >

Token Based Authentication for Web API's

Securing ASP.NET Web API using Custom Token Based AuthenticationProviding a security to the Web API&...

Read More >

Custom Control in WPF

File Upload Custom Control in WPFThis article is about Custom control in WPF, Custom controls are al...

Read More >

ASP.NET: Audit Trail Implementation using Entity Framework

When you are working with certain projects which involves the Customer records, you might need to tr...

Read More >

Create Restful service using Web API

What is Asp.Net Web API?Asp.Net Web API is a framework for building HTTP services that can be consum...

Read More >

Dependency Injection on SignalR

                &nbs...

Read More >

Create custom project templates in Visual Studio

Visual studio installation comes with the various predefined project templates, and we can use one o...

Read More >

Share

Try DevOpSmartBoard Ultimate complete Azure DevOps End-to end reporting tool

Sign Up

  • Recent
  • Popular
  • Tag
Tags
Monthly Archive
Subscribe
Name

Text/HTML
Text/HTML
Contact Us
  • *
  • *