For a general introduction to developing features for mojoPortal, see the overview article.
The mojoPortal Web project uses the Web Application project type in Visual Studio. In this model, C# code is not inline in the page, it is in codebehind files which are then compiled and the libraries are placed in the bin folder. Using this model, you typically do not deploy the C# source code on production servers. Not deploying source code has some security benefits but the tradeoff is that you can't just edit the code on the server, you must compile it and redeploy the DLLs.
Sometime you may have the need for a simple module and compiling is a bit overkill. It is possible, and very easy, to create .ascx ModuleControls and supporting .aspx pages with inline code and use them in your mojoPortal development. When using inline code, all the code is self-contained within the .ascx/.aspx file and there are no related code behind files. Instead, the code is embedded in the page in <script runat="server"> </script>
The ModuleControl is the part that plugs into a page in the content system. When you add a feature to a page you are putting its ModuleControl on the page.
Here is a template that you can use as a starting point for the ModuleControl for a simple mojoPortal feature:
C# Example
<%@ Control Language="C#" ClassName="MyCustomSiteModule.ascx" Inherits="mojoPortal.Web.SiteModuleControl" %>
<%@ Import Namespace="mojoPortal.Business" %>
<%@ Import Namespace="mojoPortal.Business.WebHelpers" %>
<%@ Import Namespace="mojoPortal.Web.Framework" %>
<%@ Import Namespace="mojoPortal.Web.Controls" %>
<%@ Import Namespace="mojoPortal.Web.Editor" %>
<%@ Import Namespace="mojoPortal.Net" %>
<script runat="server">
/*
* Custom Settings can be created with a setup file or by manual entry.
* Setup File: https://www.mojoportal.com/using-the-installation-system
* Manual Entry: Simply browse to Administration > Advancted Tools > Features
*/
private int settingInt = -1;
private bool settingBool = false;
private string settingString = "default";
private string settingCssClass = String.Empty;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
protected void Page_Load(object sender, EventArgs e)
{
LoadSettings();
PopulateLabels();
PopulateControls();
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "Hello Web";
}
private void PopulateControls()
{
TextBox1.Text = "Click the button";
}
private void PopulateLabels()
{
}
private void LoadSettings()
{
// TODO: if yous feature has an edit page link to it here
//Title1.EditUrl = SiteRoot + "/MyClassEdit.aspx";
//Title1.EditText =
Title1.Visible = !this.RenderInWebPartMode;
if (this.ModuleConfiguration != null)
{
this.Title = this.ModuleConfiguration.ModuleTitle;
this.Description = this.ModuleConfiguration.FeatureName;
}
//Get our Custom Settings
settingInt = WebUtils.ParseInt32FromHashtable(Settings, "CustomModuleSettingInt", settingInt);
settingBool = WebUtils.ParseBoolFromHashtable(Settings, "CustomModuleSettingBool", settingBool);
if (Settings.Contains("CustomModuleSettingString"))
{
if (Settings["CustomModuleSettingString"].ToString() != string.Empty)
{
settingString = Settings["CustomModuleSettingString"].ToString();
}
}
if (Settings.Contains("CustomModuleSettingCssClass"))
{
if (Settings["CustomModuleSettingCssClass"].ToString() != string.Empty)
{
settingCssClass = Settings["CustomModuleSettingCssClass"].ToString();
}
}
pnlOuterWrap.SetOrAppendCss(settingCssClass);
}
</script>
<portal:OuterWrapperPanel ID="pnlOuterWrap" runat="server">
<portal:InnerWrapperPanel ID="pnlInnerWrap" runat="server" CssClass="panelwrapper htmlmodule">
<portal:ModuleTitleControl id="Title1" runat="server" EditUrl="/Modules/HtmlEdit.aspx" EnableViewState="false" />
<portal:OuterBodyPanel ID="pnlOuterBody" runat="server">
<portal:InnerBodyPanel ID="pnlContent" runat="server" CssClass="modulecontent">
Your custom form goes here.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br/>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /><br/>
settingInt = <%= Convert.ToString(settingInt) %><br/>
settingBool = <%= Convert.ToString(settingBool) %><br/>
settingString = <%= settingString %><br/>
</portal:InnerBodyPanel>
<portal:EmptyPanel id="divFooter" runat="server" CssClass="modulefooter" SkinID="modulefooter"></portal:EmptyPanel>
</portal:OuterBodyPanel>
<portal:EmptyPanel id="divCleared" runat="server" CssClass="cleared" SkinID="cleared"></portal:EmptyPanel>
</portal:InnerWrapperPanel>
</portal:OuterWrapperPanel>
This is a basic example. Create a text file, paste this in, save as a YourFeatureName.ascx in the Web/Modules folder, then "install" it in the site by using the installation system or manually at Administration Menu > Advanced Tools > Features. Give it a name and set the path to your .ascx file. Now it will show up in the Features dropdown list.
Last Modified by Joe Davis on Dec 03, 2020