When you create Lemoon templates, you can use Web Server and User Controls just like you would in a standard ASP.NET Web Forms application.

  • Web Server Controls Web server controls are objects on ASP.NET Web pages that run when the page is requested and that render markup to the browser. Many Web server controls are similar to familiar HTML elements, such as buttons and text boxes. Other controls encompass complex behavior, such as calendar controls.

  • User Controls In addition to using Web server controls in your ASP.NET Web pages, you can create your own custom, reusable controls using the same techniques you use for creating ASP.NET Web pages. These controls are called user controls.

Controls are only needed if you want to re-use the same functionality in different places. One example could be a commenting control that should be used for more than one content type. Since every content type usually has its own template, you don't want to implement the commenting functionality on every template. Instead you should create a control which implement the functionality and use the control on the templates.

Controls in Lemoon should inherit from WebControlBase or UserControlBase<T>. to take full advantage of the rendering flow where properties like Content and Site are available.

The examples below shows a user control and a template that uses the control.

using System;
using System.Linq;
using System.Web.UI;
using Mindroute.Core.Model;
using Mindroute.Lemoon.Helpers;
using Mindroute.Lemoon.Web.UI;
namespace MyProject.Lemoon.UserControls {
    public partial class Comments : UserControlBase<Content> {
            protected override void OnInit(EventArgs e) {
            this.Visible = Content.Commenting != Commenting.Disabled;
<%@ control language="C#" autoeventwireup="true" codebehind="Comments.ascx.cs" inherits="MyProject.Lemoon.UserControls.Comments" %> 

<ul class="comments">
<% foreach (var comment in Content.Comments) { %>
<li><%= comment.Body.HtmlSafe(true).Linkify() %></li>
<% } %>

Example 1. A web user control.

<%@ page language="C#" masterpagefile="~/Lemoon/MasterPages/Site.Master" autoeventwireup="true" codebehind="BlogEntryTemplate.aspx.cs" inherits="MyProject.Lemoon.Templates.BlogEntryTemplate" %>
<%@ register tagprefix="controls" tagname="comments" src="~/Lemoon/UserControls/Comments.ascx" %>
<asp:content contentplaceholderid="mainplh" runat="server">
  <h1><%: Content.Title %></h1>
  <%= Content.Body %>
  <controls:comments runat="server" />

Example 2. A template that uses the web user control.