Create the code-behind

NEW TO SITEFINITY?

To do this, perform the following:

  1. Add a class and name it MyCustomSettings.cs
  2. In the class, paste the following code:
    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?

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?