User Controls

There are times when you need to expose some of mojoPortal’s inner logic that isn’t otherwise accessible from, eg, the layout.master file.  To do so, just create a user control and import it into the master page.  Eg, if you needed to grab just the page name (as I did ), you would create something as follows:

In layout.master below the page directives:

<%@ Register Src="PageNameControl.ascx" TagName="PageNameControl" TagPrefix="CustomControl" %>

Then add the control in the layout.master content:

<CustomControl:PageNameControl id="pn1" runat="server" />

Then the code for a simple UserControl would be:

<%@ Control Language="C#" AutoEventWireup="true" ClassName="PageNameControl.ascx" Inherits="System.Web.UI.UserControl" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="mojoPortal.Business" %>
<%@ Import Namespace="mojoPortal.Business.WebHelpers" %>
<%@ Import Namespace="mojoPortal.Web.Framework" %>
<%@ Import Namespace="mojoPortal.Web.Controls" %>


<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
PopulateControls();
}

private void PopulateControls()
{
PageSettings currentPage = CacheHelper.GetCurrentPage();
if(currentPage == null){ return; }
lblPageName.Text = currentPage.PageName;

}

</script>

<asp:Label ID="lblPageName" runat="server" />