IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
The custom controls are independent from the project, which they are being used in. They consist of a single dll, which can be reused across different applications.
To create a control of this type, you must first create an empty custom control. The control can reside in Sitefinity solution or in another solution. You will create a control in the scope of the Sitefinity's solution.
To create an empty custom control, perform the following:
From the dialog choose Visual C# » Web » ASP.NET Server Control.
Name the project NewsRotator and click OK.
A new project is generated under the solution. It contains only a single .cs file named ServerControl1.
Rename the file to NewsRotator.cs. You must also rename the class name inside the file to NewsRotator.
NOTE: Make sure your class library targets version 4.0 of the .NET Framework. To verify right-click the NewsRotator class library and select Properties. From the Application menu item, select the target framework.
Open the file and remove any auto-generated code besides the class definition. The code inside your NewsRotator.cs file must look like this:
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Linq;
System.Text;
System.Web;
System.Web.UI;
System.Web.UI.WebControls;
namespace
NewsRotator
{
public
class
NewsRotator : WebControl
}
In Sitefinity, you can create your controls as standard ASP.NET custom controls or you can derive them from one of the built-in base classes - SimpleView, SimpleScriptView. They provide you with additional features, which, for example, are not available in the WebControl class.
In this tutorial you derive the NewsRotator control from the SimpleView class. To do this, you must add a reference to theTelerik.Sitefinity.dll in your NewsRotator project. To do so, follow these steps:
Open the NewsRotator.cs and import the following using statement: using Telerik.Sitefinity.Web.UI;
Modify the class definition to the following:
NewsRotator : SimpleView
protected
override
void
InitializeControls(GenericContainer container)
throw
new
NotImplementedException();
string
LayoutTemplateName
get
For the project to compile at this stage, you must also override the InitializeControls abstract method and the LayoutTemplateNameproperty.
The InitializeControls method is the place where you must address the UI elements, which are placed in a template of the control. TheLayoutTemplateName specifies the name for the default template of your control.
You must reference the control's assembly in the Sitefinity project. In this tutorial the control and Sitefinity project are located in one and the same solution. To add a reference, perform the following:
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important