Create the code-behind
To do this, perform the following:
- Add a class and name it
MyCustomSettings.cs - In the class, paste the following code:
C#
using System.Web.UI; using Telerik.Sitefinity.Web.UI; using Telerik.Sitefinity.Web.UI.Fields; namespace SitefinityWebApp.CustomSettings { public class MyCustomSettings : SimpleView { #region Properties /// <summary> /// Obsolete. Use LayoutTemplatePath instead. /// </summary> protected override string LayoutTemplateName { get { return string.Empty; } } protected override HtmlTextWriterTag TagKey { get { //we use div wrapper tag to make easier common styling return HtmlTextWriterTag.Div; } } /// <summary> /// Gets the layout template's relative or virtual path. /// </summary> public override string LayoutTemplatePath { get { if (string.IsNullOrEmpty(base.LayoutTemplatePath)) return MyCustomSettings.layoutTemplatePath; return base.LayoutTemplatePath; } set { base.LayoutTemplatePath = value; } } #endregion #region Control References /// <summary> /// Reference to the Label control that shows the Message. /// </summary> protected virtual ChoiceField RandomVariable { get { return this.Container.GetControl<ChoiceField>("randomVariable", true); } } #endregion #region Methods /// <summary> /// Initializes the controls. /// </summary> /// <param name="container"></param> /// <remarks> /// Initialize your controls in this method. Do not override CreateChildControls method. /// </remarks> protected override void InitializeControls(GenericContainer container) { this.RandomVariable.Choices.Add(new ChoiceItem { Text = "first option", Value = "first option" }); this.RandomVariable.Choices.Add(new ChoiceItem { Text = "second option", Value = "second option" }); this.RandomVariable.Choices.Add(new ChoiceItem { Text = "third option", Value = "third option" }); } #endregion #region Private members & constants public static readonly string layoutTemplatePath = "~/MyCustomSettings.ascx"; #endregion } }
NOTE: In the above class, you define the path to the template as virtual path.
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your 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 ASP.NET Core and take advantage of its decoupled architecture and modern development model.