Define Master/Detail view for a custom control in Sitefinity

You can define a Master/Detail view for a custom control in Sitefinity in many ways. One possible way would be your custom control to inherit from ContentView class, described in the Sitefinity forum post here.

This blog post will demonstrate an easier and quicker approach.

Step 1: Create a public boolean property in the control with name IsDetailsMode:

    /// <summary>
    /// Gets or sets a value indicating whether this instance is details mode.
    /// </summary>
    /// <value>
    /// <c>true</c> if this instance is details mode; otherwise, <c>false</c>.
    /// </value>
    public bool IsDetailsMode
    {
        get
        {
            return this.isDetailsMode;
        }
        set
        {
            this.isDetailsMode = value;
        }
    }

Step 2: Use Sitefinity Thunder to generate control designer as described in Sitefinity official documentation.

Step 3: The property is set in the designer by the content editors. You rely on this property to render different template:

  protected override void CreateChildControls()
    {
        if (this.IsDetailsMode)
        {
            this.LayoutTemplatePath = this.layoutTemplatePathDetails;
        }
        else
        {
            this.LayoutTemplatePath = this.layoutTemplatePathMaster;
        }

        base.CreateChildControls();
    }

If the value of the property in the designer is not changed, by default the custom control will render the Master view.

TIP: With this approach please note that all control references must not be required!

Veronica Milcheva

About Veronica Milcheva

I am a passionate Sitefinity blogger, developer and consultant. In my spare time I enjoy running and listening to music. My personal quote: There's no tough problem, just not enough coffee :)

View Comments

comments powered by Disqus