Using Inline Code

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 into mojoPortal.Web.dll 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.

Some developers may wish for the easy tweakability of inline code so I will explain here how it is possible to create .aspx pages with inline code and use them in your mojoPortal development. When using inline code, all the code is self contained within the .aspx file and there are no related code behind files. Instead the code is embedded in the page in <script runat="server"> </script>

Below is a skeleton Hello World example. Just create a text file with a .aspx extension and copy and paste the below example as a starting point. Make sure the page name does not conflict with any existing pages and just drop it in to your web folder. Next create a new page in the content system and in the page settings set the Url property to point to your physical page. I think you can use the "~/pagename.aspx" syntax for te url but I'm sure you can use a fully qualified url.

<%@ Page Language="C#"
ClassName="ExampleInlineCodePage"
Inherits="mojoPortal.Web.mojoBasePage"
MasterPageFile="~/App_MasterPages/layout.Master" %>

<%@ 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">

protected override void OnPreInit(EventArgs e)
{
this.allowSkinOverride = true;
base.OnPreInit(e);
}

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.SuppressPageMenu();
}

protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = "Click the button";

}

protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "Hello Web";
}

</script>

<asp:Content ContentPlaceHolderID="leftContent" ID="MPLeftPane" runat="server" />
<asp:Content ContentPlaceHolderID="mainContent" ID="MPContent" runat="server">
Your custom form goes here.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>

</asp:Content>
<asp:Content ContentPlaceHolderID="rightContent" ID="MPRightPane" runat="server" />
<asp:Content ContentPlaceHolderID="pageEditContent" ID="MPPageEdit" runat="server" />

 

mojoPortal Wins the 2007 Open Source CMS Awards Best Non-PHP Open Source CMS Donate Money to support the mojoPortal Project. Join the mojoPortal Group on Facebook Join the mojoPortal Group on LinkedIn View Joe Audette's profile on LinkedIn View Joe Audette's profile on The Guild of Accessible Web Designers site mojoPortal can run on GNU/Linux using Mono