NewsRotator widget: Create an empty custom control

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 CMS 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:

  1. In the context menu of Sitefinity CMS solution, click Add » New project...
  2. In the dialog choose Visual C# » Web » ASP.NET Server Control.
  3. Name the project NewsRotator and click OK.
    A new project is generated under the solution. It contains only a single .cs file.
  4. Rename the file to Rotator.cs.
    You must also rename the class name inside the file to Rotator.

    NOTE: Make sure your class library targets the same .NET framework version as your project. To verify right-click the NewsRotator class library and select Properties. In the Application menu item, select the target framework.

  5. Open the file and remove any auto-generated code besides the class definition.

Inherit the SimpleView class

In Sitefinity CMS, you can create your controls as standard ASP.NET custom controls or you can derive them from one of the built-in base classes - SimpleViewSimpleScriptView. 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 Telerik.Sitefinity.dll in your NewsRotator project.
Perform the following:

  1. In the context menu of project NewsRotator, click Add Reference...
  2. In the dialog select the Browse tab.
  3. The Telerik.Sitefinity assembly is located in folder Telerik.Sitefinity.Samples.Dependencies.
    Select it and click OK.
  4. Open the NewsRotator.cs and import the following using statement: using Telerik.Sitefinity.Web.UI;
  5. Modify the class definition by overriding 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. The LayoutTemplateName specifies the name for the default template of your control.

EXAMPLE: For more information about the code of the Rotator.cs file, see NewsRotator widget: Code of the control class.

Reference the control

You must reference the control's assembly in the Sitefinity CMS project. In this tutorial, the control and Sitefinity CMS project are located in one and the same solution. To add a reference, perform the following:

  1. In the context menu of SitefinityWebApp project, click Add Reference...
  2. Click Projects tab.
  3. Select the NewsRotator project and click OK.
    The reference is added and you can register and use the custom control in your Sitefinity CMS application.

Was this article helpful?