Use this procedure to wire up the created template and the control itself.
To specify a default template for the control, you must override the LayoutTemplateName property in the NewsRotator class. It must return a string that represents a reference to the embedded resource that represents your template. When NewsRotator widget: Create a template, you created a template named Rotator.ascx. To reference it, use the following code:
The LayoutTemplateName follows the naming convention <Namespace>.<ResourceFolderPath>.<TemplateName>, where you must replace path slashes inside the resource folder path with dots.
In addition to the LayoutTemplateName, the SimpleView exposes the LayoutTemplatePath property. It is used to refer an external template that is placed outside of the assembly. If you do not set LayoutTemplatePath property, you give the users the ability to use their own templates instead of the embedded template. With this feature of custom controls, the users are able to adjust the looks of the control with minimal amount of work.
The SimpleView attempts to load the template located at LayoutTemplatePath value, but falls back to the LayoutTemplateName value, if there is no path provided, or the template could not be found. This provides customization while, at the same time, preserves stability in case the user input was wrong.
The template that you defined in NewsRotator widget: Create a template, 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.
Following is the code for the property:
The template, you provided, is instantiated inside the Container object, that handles all the logic for managing the template. Use itsGetControl<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 theEnsureChildControls() method before every reference to a template control.
Back To Top