This topic describes how to create a simple custom intra-site module. In order to demonstrate a simple example of how to build an intra-site module, a custom module is
built that only displays a message in the Administrative part of Sitefinity.
 |
You could download an archived version of the Custom Intra-Site Module HERE . |
Demo Intra-Site Module
The Demo intra-site module demonstrates implementation of a custom intra-site module for Sitefinity. The module only displays messages and buttons in order to
show the simplicity of implementation of the module. The following items are included:
- IntraDemo.cs class - situated in the App_Code folder.
IntraDemo is the module class that derives from the Telerik.WebModule class which enables the custom module to be recognized by the Sitefinity
framework.
- User controls - they are situated in the Demo folder. These are the user interface elements for both administering the module and including it
to Sitefinity pages. The user controls are:
Following is the Administrative part of the Demo intra-site module:
Figure 1
Creating the Module Class
In order for the custom module to be recognized by Sitefinity a module class must be created that derives from the Telerik.WebModule class. When the Sitefinity
Web site is loaded, the Telerik framework scans for classes based upon the WebModule class and adds them to the available modules.
To create the module class, follow the instructions:
- Right-click on the App_Code folder, and then select Add New Item.
- Select Class, then enter a name for the class. In this example, the class is called IntraDemo.
- Inherit from the Telerik.WebModule class.
| IntraDemo.cs |
Copy Code |
|
using System; using System.Data; using System.Configuration; using
System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Telerik; using
Telerik.Cms; using Telerik.Cms.Web.UI; using Telerik.Web; /// <summary>
/// Summary description for IntraDemo
/// </summary> public class IntraDemo : Telerik.WebModule
{
public IntraDemo()
{
// TODO: Add constructor logic here
}
#region Class Variables
private System.Collections.Generic.IList<Telerik.Web.IToolboxItem>
toolboxItems;
#endregion Class Variables
#region Properties
/// <summary>
/// Name of the module.
/// </summary>
public override string Name
{
get { return "Intra-site Control"; }
}
/// <summary>
/// Title of the module that is displayed in navigation.
/// </summary>
/// <remarks>
/// Store/retrieve the value in the resource file.
/// </remarks>
public override string Title
{
get { return "Demo Intra-site Module"; }
}
/// <summary>
/// Description of the module.
/// </summary>
/// <remarks>
/// Store/retrieve the value in the resource file.
/// </remarks>
public override string Description
{
get { return "A module."; }
}
/// <summary>
/// Gets ToolboxItemCollection with all ToolboxItem objects which register the
/// corresponding control for use in the public part of Sitefinity. These controls
/// are available for insertion into a page.
/// </summary>
public override System.Collections.Generic.IList<Telerik.Web.IToolboxItem> Controls
{
get
{
if (toolboxItems == null)
{
//Register the Module control for public use.
//Add additional controls here.
toolboxItems =
new System.Collections.Generic.List<Telerik.Web.IToolboxItem>(
new Telerik.Web.ToolboxItem[]
{
new CmsToolboxItem("~/Demo/WebUserControl.ascx", "PublicCDemo", "Button1", "Show
no information.")
}
);
}
return toolboxItems;
}
}
#endregion Properties
#region Methods
/// <summary>
/// Creates the ControlPanel object for the Demo module administration.
/// </summary>
/// <returns>Instance of the ControlPanel object of the module.</returns>
public override Control CreateControlPanel(TemplateControl
parent)
{
return parent.LoadControl("~/Demo/ControlPanel.ascx");
}
#endregion
} public interface IDemoControlPanel
{
//implement your custom interface here
}
|
The WebModule class and its base classes contain abstract properties and methods that must be implemented in the new module class.
ControlPanel User Control
The primary functionality for administering the module is contained in the ControlPanel.ascx file. This file must implement the
Telerik.IControlPanel interface in order to be loaded into the Sitefinity administrative user interface.
The ControlPanel should contain any administrative or setup functionality for the module. In the sample Demo module, the ControlPanel is used to display a textbox and a
checkbox. The functionality is contained in the ControlPanel which only someone with administrative privileges is authorized to access. Figure 1 illustrates how is the ControlPanel.ascx user control applied and displayed on the
administrative page.
The ControlPanel.ascx user control implements the Telerik.Web.IControlPanel interface. The abstract properties and methods
implemented in ControlPanel.ascx allow the control to be integrated into the Sitefinity framework.
| ControlPanel.ascx |
Copy Code |
|
using System; using System.Collections; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using Telerik.Web; using Telerik; public partial class demo_ControlPanel : System.Web.UI.UserControl, Telerik.Web.IControlPanel
{
protected void Page_Load(object sender, EventArgs e)
{
}
#region IControlPanel Members
public ICommandPanel[] CommandPanels
{
get { return new ICommandPanel[] {
(ICommandPanel)this.Page.LoadControl("~/Demo/CommandPanel.ascx") }; }
}
public void Refresh()
{
throw new NotImplementedException();
}
public string Status
{
get { return "Demo Intra-site Module
Status"; }
}
public string Title
{
get { return "Demo Intra-site Module
Title"; }
}
#endregion
}
|
Telerik.Web.IControlPanel Interface
The ControlPanel control implements the Telerik.Web.IControlPanel interface, and
inherits the System.Web.UI.UserControl class.
Namespace: Telerik.Web
Assembly: Telerik.Framework
Inheritance Hierarchy
- Telerik.Web.IControlPanel
Members
Methods and Properties
| Name |
Type |
Description |
| Status |
string |
The standard status message displayed for the control panel. |
| Title |
string |
The title displayed for the control in the control panel section of the administrative page.
|
| CommandPanels |
ICommandPannel[] |
Gets an instance of the command panels connected to the control panel. |
| Refresh |
void |
Refreshs the control hierarchy of the control; recreates the controls' child controls. |
CommandPanel User Control
The CommandPanel.ascx control is a companion to the ControlPanel in the standard Sitefinity administrative page layout. As the name implies, it is a
control that is situated in the Command Panel (left panel) that control the main administrative functionality of the ControlPanel. In the sample Demo module the
CommandPanel user control displays a message. Figure 1 illustrates how is the
CommandPanel.ascx user control applied and displayed on the administrative page.
The CommandPanel control must inherit from the Telerik.ICommandPanel interface to be loaded into the Sitefinity administrative user interface.
| CommandPanel.ascx |
Copy Code |
|
using System; using System.Data; using System.Configuration; using
System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Telerik.Web; public partial class Demo_CommandPanel : System.Web.UI.UserControl,
ICommandPanel
{
protected void Page_Load(object sender, EventArgs e)
{
}
#region ICommandPanel Members
public IControlPanel ControlPanel
{
get { throw new NotImplementedException(); }
}
public string Name
{
get { return "Demo Intra-site Module
Name"; }
}
public void Refresh()
{
throw new NotImplementedException();
}
public string Title
{
get { return "Demo Intra-site Module
Title"; }
}
#endregion
}
|
Telerik.ICommandPanel Interface
All Command Panlel controls must derive from this interface in addition to System.Web.UI.UserControl to function properly in Sitefinity.
Namespace: Telerik
Assembly: Telerik.Framework
Inheritance Hierarchy
Members
Public Properties
| Name |
Description |
| ControlPanel |
The control panel associated with the command. |
| Name |
Name of the control. |
| Title |
Title of the control. |
| Refresh |
not implemented yet |
How Does the CommandPanel Control Work?
There is a message displayed in the panel in place of links that will implement the functionality of an intra-site module. The message is saved in the ascx file.
| CommandPanel.ascx |
Copy Code |
|
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CommandPanel.ascx.cs" Inherits="Demo_CommandPanel" %>
<asp:HyperLink ID="HyperLink1" runat="server">This is the Demo Module Command Panel</asp:HyperLink>
|
Loading the ControlPanel and CommandPanel
In the Telerik.WebModule base class there are two abstract methods which need to be implemented. These two methods load the ControlPanel and CommandPanel
user controls into the Sitefinity administrative user interface. As the names imply, CreateControlPanel() loads the ControlPanel control while
CreateCommandPanelControls() loads the CommandPanel control.
The method CreateControlPanel creates the ControlPanel object for the Demo module administration and returns an instance of the ControlPanel object of the
module. The method CreateCommandPanelControls creates the controls for the Demo module administrative command panel and returns an array of controls for the Demo
module command panel.
 |
The CreateCommandPanelControls is an array so multiple controls can be loaded into the
CommandPanel on the administrative page. |
As of Sitefinity 3.2, the module class only loads the ControlPanel control. The CommandPanel control is loaded in the ControlPanel class. This way, the
administrative and public parts of the implementation of the module are not only logically but also physically separated within the module.
Web User Control
The Web User Control appears in the toolbox in Page Edit in the Demo Intra-site Module region (see Figure 2). The Demo module includes this simple Web
user control only to aid in the demonstration of building an intra-site module. The control displays a button, and when the button is pressed, a message appears. The control
should be extended in order to provide a more complicated logic of the module.
Figure 2
The .cs file contains the Button1_Click method that displays the message:
| WebUserControl.ascx.cs |
Copy Code |
|
public partial class Demo_WebUserControl :
System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("Web User Control");
}
}
|
The .ascx file contains the button ASP control which is displayed by the user control:
| WebUserControl.ascx |
Copy Code |
|
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="Demo_WebUserControl" %>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Demo Button"
Width="255px" />
|
See Also