Extending an existing control provided in Sitefinity is useful and time-saving - customizing existing controls take less time than creating new ones from scratch. The
functionality the controls offer is prone to extension but it is up to each customer to define the exact requirements. This topic will provide an example for
extending controls in Sitefinity by adding the Generic Content control to a user control.
Entering content is the main functionality of the Generic Content control. Still, additional options such as choosing what to be visible to whom or when it should be
visible are very useful. This would come in handy when setting different content of a page for registered and for unregistered users.
A user control could wrap an existing GenericContent control, and implement the custom logic. The user control should implement
IContentContainer interface and its Content property should have an appropriate WebEditor attribute. For example:
| UserControls_ExtGenericContent.ascx |
Copy Code |
|
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ExtGenericContent.ascx.cs" Inherits="UserControls_ExtGenericContent" %> <%@ Register Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls"
TagPrefix="sfWeb" %>
<sfWeb:GenericContent runat="server" ID="GenericContent1"
/>
|
| UserControls_ExtGenericContent.ascx.cs |
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.Cms; using Telerik; using Telerik.Cms.Engine.WebControls; using System.ComponentModel; using Telerik.Cms.Web.UI;
public partial class UserControls_ExtGenericContent : System.Web.UI.UserControl, IContentContainer
{
protected void Page_Load(object sender, EventArgs e)
{
}
#region IContentContainer Members
[Browsable(false)]
[WebEditor("Telerik.Cms.Engine.WebControls.HtmlContentEditor, Telerik.Cms.Engine")]
[TypeConverter(typeof(StringConverter))]
public object Content
{
get
{
return this.GenericContent1.Content;
}
set
{
this.GenericContent1.Content =
value;
}
}
public string ProviderName
{
get
{
return this.GenericContent1.ProviderName;
}
set
{
this.GenericContent1.ProviderName =
value;
}
}
#endregion
}
|
 |
The above implementation works for all Sitefinity versions except for one - 3.0. Instead of
UserControl you should use a compiled WebControl in order to apply the example in Sitefinity 3.0.
|