Hello World - Developer Quick Start

Last Modified 2010-09-18

This article is meant to help you get going and get results quickly with mojoPortal CMS. If you already know how to implement a UserControl in ASP.NET then you already know how to build something that can plug into a mojoPortal CMS page, so you're going to find this very easy.

First you need to understand a basic concept about mojoPortal and other content management systems, PAGES IN THE SITE MENU DO NOT CORRESPOND TO PHYSICAL FILES. Pages are built dynamically from database content and all pages in the menu are served by Default.aspx in the root of the web. mojoPortal knows what features to load based on the database information. When you create a page in mojoPortal, then you click the pencil to add things to the page you see a dropdown list of available features. So I'm going to show you how to add your custom feature to that list and then when you add your custom feature to a page mojoPortal will know how to load it. Even better I'm going to give you some starter code that you can drop in and then modify to get going.

Prerequisites

I assume you already have the mojoPortal source code (ideally from svn trunk) and Visual Studio and you have it working on your machine so you can get mojoPortal running in the browser either using the Visual Studio built in web server or IIS.

Hello World Code Samples

Download this file: mojoPortal-EasyHelloWorldExamples.zip

Unzip the file and then copy the folder "MyCustomModules" into your /Web folder. You'll note there are 2 files in this folder which are the hello world examples to get you going:
HelloMojoSiteModule.ascx
HelloMojoUserControl.ascx

The only difference between them is that HelloMojoSiteModule.ascx inherits from a mojoPortal base class named SiteModuleControl which itself inherits from UserControl, whereas HelloMojoUserControl.ascx inherits directly from UserControl. Both examples also illustrate the use of ASP.NET UpdatePanel for ajax postbacks.

The main benefit of inheriting from our base class is because it provides you some internal properties that are needed if your feature is going to support different instances with different content. The main property of interest is ModuleId which is basically the instance id. So for example the Blog feature supports multiple instances. You can put a blog on one page and another blog on another page and they are completely separate blogs. They keep track of which data they are supposed to show by storing the ModuleId in the mp_Blog table and each instance retrieves its own content by passing in its own ModuleId.

So if your feature isn't going to need to support multiple instance you could just use a plain UserControl instead of inheriting from SiteModuleControl. There is no harm in inheriting from SiteModuleControl even if you aren't going to implement multiple instance support in your feature so its really up to you. mojoPortal assigns a ModuleId and tracks your UserControl by a ModuleId anyway. The only difference is the plain UserControl doesn't know what ModuleId it has but SiteModuleControl does know about its own ModuleId and can use it internally.

Important: When developing features that will use postback right in the UserControl/SiteModuleControl of the feature, you typically will need to call Page.EnableViewstate = true; in page load or init because we set it to false by default to avoid viewstate when it is not needed.

Installing The Hello World Examples

Enough talk, lets get some action shall we? So you now have the example files under Web/MyCustomModules, the first thing we need to do is tell mojoPortal about the existence of these custom features. We will install them one at a time, but its the same steps for each one. Its very easy.

  1. Click the Administration link to get to the Administration Menu, then choose Advanced Tools > Feature Installation/Configuration
  2. Click the "Add New Feature" link at the bottom of the page.
  3. For the Feature Name put "Hello Mojo SiteModule"
  4. For the Control Source setting put MyCustomModules/HelloMojoSiteModule.ascx
  5. Click the Update Button to save the new feature

Next lets go ahead an install the UserControl example.

  1. Click the Key Icon to get to the Administration Menu, then choose Advanced Tools > Feature Installation/Configuration
  2. Click the "Add New Feature" link at the bottom of the page.
  3. For the Feature Name put "Hello Mojo UserControl"
  4. For the Control Source setting put MyCustomModules/HelloMojoUserControl.ascx
  5. Click the Update Button to save the new feature

Now these items will show up in the list of things you can put on a page. Optionally, create a new page to test them on, or use an existing page. Once the page is created click the pencil icon to get to the page layout page where you can add features to a page. Add one of each of the hello world examples to the page, then view the page. Voila! you should have both examples on the page and working.

Next Steps

I used the inline code instead of code behind approach to make these examples because its easier to share them that way and easier to get started. There is really nothing terribly wrong with the inline code approach, but myself I generally use the code behind model (where the code is pre-compiled into dlls in the bin folder) in my own development and I put my code in separate projects and use post build events to copy them to the Web folder. I also use separate class library projects for my business classes and data access code. If you read the rest of the documentation and watch the videos you can learn how to do things the way I really recommend doing them. But I know in the real world people often need to get results quickly and not being as familiar with mojoPortal as I am developers can find it overwhelming trying to get going with my other documentation. This quick start hello world article is meant to help. Now all you have to do is open up the HelloMojoSiteModule.ascx or HelloMojoUserControl.ascx file in Visual Studio (or you can even use a text editor if you know C# well enough). Just add your own custom logic to do what you need.

Common Problems You May Encounter

See this thread for a common issue about an error on postback to the url /

It happens in Visual Studio but not in IIS but it may throw you off if you don't know about it.

I hope this article helps you. Have fun with mojoPortal and happy coding!

Rate this Content 69 Votes