NewsRotator widget: Reference the template in the custom control

Use this procedure to wire up the created template and the control itself.

Specify the template

To specify a default template for the control, you must override the LayoutTemplatePath property in the Rotator class. It must return a string that represents a reference to the embedded resource that represents your template.

The LayoutTemplatePath follows the naming convention <Namespace>.<ResourceFolderPath>.<TemplateName>, where you must replace path slashes inside the resource folder path with dots.

Get a reference of the RadRotator control

 

The template that you defined uses the RadRotator control for its main UI element. When you implement the features of the control, you will need an instance of that control to pass the news items to it or to set the various properties. You must create a property that returns the instance of the RadRotator control in your template. To use RadRotator control in code, you must import the using Telerik.Web.UI; statement.

The template, you provided, is instantiated inside the Container object, that handles all the logic for managing the template. Use its GetControl<T> method to find the RadRotator1 control. To pass the ID of the control and whether it is required, you must use the third overload of the method. In this case, you require the control's instance, because the controls relies on it. If there is no RadRotator1 control in the provided template the control throws an exception. To avoid this behavior, you can set the required parameter to false.

NOTE: When using templates make sure you address the controls after they have been initialized. The place, where the template is initialized and ready to use, is the InitializeControls method. In it and after its execution, you can safely call your controls. You can call the EnsureChildControls() method before every reference to a template control.

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

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?