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.

Module Custom Code

In this lesson we will lean about a very important section which is provided in M# to implement custom code e.g. Initialization Code, Properties, Methods, and JavaScript etc.

M# allows custom code to be implemented under heading “Code” in each module, as shown in the screenshot below:

Note: Properties section is discussed in the next lesson. In this lesson we will take a look on the rest of the section one by one.

Class Code

This section is used to write custom code in module to perform some UI related tasks. You should only use this section to write small UI helper methods and all the business logic or database related methods should be written in “Model”. Also you should avoid using it to generate public Properties as M# provides a separate section “Properties” for this and should be used instead. (For more information on properties please read lesson Module Properties in chapter 7)

Css Styles

This section is used define custom css styles for the module. Any css styles defined in this section are embedded in the module inside “style” tag.

Initialization

This section is for writing custom initializing code. Any code written in this section is generated in the “OnInit” event.

JavaScript

M# allows developers to embed JavaScript code on the module thought this section. Any code written here is embedded inside “Script” tag and is placed at the bottom of module mark-up. This section should only be used for module specific purposes. For any JavaScript code which is required for multipurpose should be added to a JavaScript file.

Load

This section allows developer to write custom code in the “Load” event of the module.

PreRender

M# generates the custom code written for this section in the “PreRender” event of the module.

BeforeSave

This section is only available for “Form” type module and is used to insert any custom code just before saving the form details.

Row_Created

This section is only available in “List” modules. M# generates the code written in this section in the “gridList_RowCreated” event of the grid list. The code is only executed for “DataRow”.

Row_Databound

This section is also only available in “List” modules. M# generates the code written in this section in the “gridList_RowDataBound” event of the grid list. The code is only executed for “DataRow”.

Header_Databound

This section is also only available in “List” modules. M# generates the code written in this section in the “gridList_RowDataBound” event of the grid list and is only executed for “HeaderRow”.

Footer_Databound

This section is also only available in “List” modules. M# generates the code written in this section in the “gridList_RowDataBound” event of the grid list and is only executed for “FooterRow”.

Writing Custom Code

The steps described below are used to generate custom code for “Class Code” section. You can follow same steps to add custom code for any section explained above.

• Type the description of the code inside the required “Section” and hit “Enter”

• M# opens a code window to write the custom code, as shown below

Important: The C# code editor provided by M# supports intellisense.

• Next, write the required code and build the module. (In our case, we are using “Class Code” section which is usually used to write UI related c# methods)