M# Tutorials

Learn to build .NET applications with M#. Our step-by-step tutorials will get you up-to-speed rapidly.
If you already know ASP.NET and C#, you can master M# in a week or two.

Referencing Other Modules

Referencing one module in other is a very important feature in M# and in this lesson we will learn about reusing / referencing existing modules developed in M#.


Each module created in M# can be referenced in other modules. Referencing a module allows developer to use them at a place inside another module and allows access to public properties and methods of the referenced module.

Modules are usually referenced to reuse the functionality e.g. you have a “Form View” for payment processing and you want to use it for different payment options and want to call its method to process payment information.

Important: Multiple module hosting should always be preferred in order to reuse a module which fulfils the requirement in most of the cases (For more information on module hosting please read lesson Module Hosting in chapter 6). The only difference is that you can’t access its public methods in other modules hosted on same page. Modules should only be referenced when access to functionality is required or the module needs to be placed inside the other module because of the page design complexity.

Referencing Module

M# provides a separate section under the heading of “References” in each module and makes a developer’s life easier by providing a list of existing modules from which you can chose the module to reference. Screenshots below show referencing of a module

The screenshots above show a list module on entity “Employee”, which shows a list of all the employees and the reference section of the list module for referencing other modules.

We consider a scenario where we want to have the edit functionality for each employee in the list. Here for the purpose of demonstration we can reference a form module on entity Employee in the list module, as shown below:

M# registers the referenced module on the list module as “Asp.Net User Control”, which allows us to reference it anywhere in the list module, as shown below

Now the module is registered, we can reference it in our list module. In M# you can get the reference tag by hitting “Ctrl+R” on the reference module. M# displays the registered module reference which can be copied in order to place it in the module, as shown below

After copying the reference of a registered module we want to place it in our list module. We have used the “Footer” property of our list module, which places the reference of registered module outside the wrapper list element. As we will need to access the public properties of the referenced module, we have also given it an “Id” with which we will access it in code behind of our list module. Footer and other module properties are discussed in a later lesson Module Properties of this chapter)

At this stage, we have a page with a list of all the available employees and a form to edit the details, as shown below:

We can add a list button to display the details of the selected employee in the referenced form to edit (Module buttons are discussed in next lesson Module Buttons of this chapter). The below C# code shows the accessible properties and methods of the referenced module.