Site Press Plugins- WebParts

Site Press has the ability to include functionality and interactivity in small reusable pieces called Plugins. While these add ons are known to end users as Plugins, developers refer to them as WebParts. From here on out in the developer guide they will be referred to by their technical name, WebParts.

Site Press WebParts are built from Microsoft ASP.NET UserControls. This means that they are highly extensible and have the full power of the .NET Framework at their disposal. However, this also means that they are very easy to create. Creating a Site Press WebPart requires little more than starting with a standard .Net user control, inheriting a base class, and adding some required methods. The rest is up to you.

WebParts may be simple or complicated, some examples of WebPart functionality are:

  • Contact Forms
  • Include other .NET controls (i.e., AJAX ToolKit)
  • List database records using a .NET Repeater Control
  • Render a page property

CMSWebPart Base Class

All Site Press WebParts inherit the CMSWebPart class. It is through the inheriting of this base class that Site Press is able to inspect WebParts for various properties and methods to determine how to render it.

The CMSWebPart base class itself inherits from System.Web.UI.UserControl, but also adds some additional methods and properties:

Property: TagName

The TagName of the WebPart is important. This directly translates to the markup that will be created for the individual WebPart. It should be unique from other WebParts in a given site. Two WebParts with the same name cannot be installed into the same site.

Property: DisplayName

This property is a placeholder for future functionality

Property: Description

This property is a placeholder for future functionality.

Property: CommandName

This property is a placeholder for future functionality.

Property: CommandArgument:

This property is a placeholder for future functionality.

Method: AssignRenderProperties()

This method must be supplied in a WebPart as it is called by Site Press at runtime to determine what the WebParts specific requirements are. This is also where the name of the WebPart is set. An example implementation of AssignRenderProperties is provided below:

// AssignRenderProperties
public override void AssignRenderProperties()
{ this.TagName = "SP3_ContactUs"; RenderProperties.Add("EmailToAddresses", new CMSWebPartProperty()
Name = "Email To Addresses",
PropertyType = typeof(string),
Value = "",
IsRequired = true

Method: IsHostedInCmsPage()

The IsHostedInCmsPage helper method is provided through the base class. It is used to determine if the WebPart is currently hosted in a Site Press page. This is primarily used during development when the WebPart is being developed in a wrapper aspx page. Used in this context, some CMS-only features are disabled.

Method: HasNoParameters()

Some WebParts use URL segments past the “host page” as parameters. This helper method (which checks IsHostedInCmsPage internally) indicates whether such parameters are available.

CMSPage and PageContent Access

Through a WebPart, developers have access to the Site Press PageContent class. Note that the IsHostedInCmsPage() method should be called first. There is a wealth of information that may be obtained from PageContent. In order to retrieve the properties of this object, cast the Page the control is on to a CMSPage. Through the newly created object, the “page” property is accessible:

var pageContent = ((Site Press3.Classes.CMSPage)this.Page).page;

Developers now have access to the Entity Framework Page model for the currently executing Page. Through this object, properties such as PageTitle, PageDescription, PageUrl, PageKeywords, and many others are accessible.

Note: While it may appear that the Entity Framework navigation properties are available as well, the Page’s Context has gone out of scope by this time and is no longer accessible.