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.

Understanding M# Layout

When you create an ASP.NET Web Application in the majority of cases you need to implement a MasterPage, which will contains all your page contents. In M# this page content is called a page and it can contains many modules. In this lesson we will learn the mark-up structure for generated pages and how they host modules.

Default layout

Create an empty page in M# and look at the generated ASPX code.

The first line corresponds to the page, the language used is C#, the title is Employee and the link to our MasterPage. In M# you can change the Title with the page attribute "Browser title" and the master page with the attribute "Master page".

The second line corresponds to your cache strategy for individual pages. By default the page is not cached, but you can change this with the help of the "Allow output cache" attribute. If set to True the OutputCache line will be deleted.

The third and fourth lines correspond to the ASP Content mark-up, it will contain your modules and will display them in the specified master page.

Modules

It's now time to add a module to our page.

The generated ASP code has changed and two new lines have been added, plus a new div section. The first one registers the module in our page and the second one display the newly registered module.

Container css

This attribute allows you to surround your module with a CSS class.

ControlID

This attribute allows you to give an ID to your module.

This is useful if you need to use your module in C#, for example when using the "Initialize statements" attribute.

Initialize statements

This attribute allows you to initialize your module and set a property present in your module. Before using this attribute you have to set the "ControlID" attribute, if you don't M# will generate a default value for you.

Tag properties

This attribute allows you to pass a value to your module. It is similar to the "Initialize statements" attribute except that it should be used for passing simple data like a boolean or integer. No code behind is generated.

Layout attributes

Master page

As discussed at the beginning of this lesson this attribute allows you to select the master page. Please refer to this lesson for more details.

Browser title

You can overwrite the title displayed by the browser with this attribute.

Allow output cache

Allows you to specify whether or not this page could be cached.

Layout

Allows you to add custom HTML content along with modules on the page. Any module can be addressed in the layout by using [#X#] where X is the ordinal number of the module on the page. See the image below.

As you can see, [#X#] tags are placeholders for modules on the page. M# replaces all [#X#] with their corresponding modules and X is the ordinal number of the module on the page. The image below shows the result of custom layout.

Maintain scroll position on postback

Keeps the scroll position after a postback event.

Root css class

Specifies a CSS class for all your modules.

Style definitions

Defines CSS styles of your page. It is rare to use this, use a stylesheet instead of setting your styles on each individual page.