More in this section

Forums / Developing with Sitefinity / Custom view to custom module

Custom view to custom module

4 posts, 0 answered
  1. Gema
    Gema avatar
    46 posts
    Registered:
    02 Oct 2009
    10 Dec 2009
    Link to this post
    Hi,
    I´ve created a custom module to work with products. Now, I want to create some views to show that products in user pages. I want to show a list of products with links to show the details (the same way NewsView). My products module work with categories, so I want my list view filters products by categories.
    I´ve seen that ListDisplay (control used by Lists module) has a behavior that fits with de one I want.

    Is it possible to inherit from ListDisplay in my custom module?
    If it is not possible, what do I have to do to create my custom listview with filters to show appropiate products?

    Thanks!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    10 Dec 2009
    Link to this post
    Hello mgrp,

    You have to create a custom control that inherits from ContentView class. Your custom class will inherit the filter functionality, so you will be able to filter all items by metakey parameters. You need to create two control templates - one for the master mode and one for the detail mode - when you click on an item.

    sample code:

    [Telerik.Framework.Web.Design.ControlDesigner("Telerik.Samples.Products.WebControls.Admin.Products.CustomDesigner")]
        public class ProductsPublicView : ContentView
        {
            /// <summary>
            /// Gets the type from the assembly containing the embedded localization resource.
            /// Override if embedded templates are using ASP.NET localization.
            /// </summary>
            /// <value></value>
            public override Type LocalizationAssemblyInfo
            {
                get
                {
                    return this.GetType();
                }
                set
                {
                    base.LocalizationAssemblyInfo = value;
                }
            }
     
            /// <summary>
            /// Gets the type from the assembly containing the embedded resources.
            /// Cannot be null reference.
            /// </summary>
            /// <value></value>
            public override Type AssemblyInfo
            {
                get
                {
                    return this.GetType();
                }
                set
                {
                    base.AssemblyInfo = value;
                }
            }
     
     
            [Category("QueryString Keys")]
            [DefaultValue(null)]
            public virtual string MyItemKey
            {
                get
                {
                    object tagKeyObj = ViewState["MyItemKey"];
                    if (tagKeyObj == null)
                        return ProductsManager.MyItemKey;
                    return (string)tagKeyObj;
                }
                set
                {
                    ViewState["MyItemKey"] = value;
                }
            }
     
            [WebSysTemplate(ProductsPublicView.ProductsViewItemListTemplateName, "ProductsViewItemListTemplateName_Desc", "/Products", true, "2009-02-17")]
            public override string ItemListTemplatePath
            {
                get
                {
                    return base.ItemListTemplatePath;
                }
                set
                {
                    base.ItemListTemplatePath = value;
                }
            }
     
            public override string ItemListTemplateName
            {
                get
                {
                    if (string.IsNullOrEmpty(this.itemListTemplateName))
                        this.itemListTemplateName = ProductsPublicView.ProductsViewItemListTemplateName;
                    return this.itemListTemplateName;
                }
                set
                {
                    this.itemListTemplateName = value;
                }
            }
     
            /// <summary>
            /// If this property is empty the control will try to detect if a provider is specified in the request or it will use the default provider.
            /// </summary>
            /// <value></value>
            public override string ProviderName
            {
                get
                {
                    object obj = ViewState["ProviderName"];
                    if(obj != null)
                        return (string) obj;
                    return ProductsManager.DefaultContentProvider;
                }
                set
                {
     
                   this.ViewState["ProviderName"] = value;
                }
            }
     
             
            protected override void CreateChildControls()
            {
     
                base.CreateChildControls()
                //ADD CUSTOM LOGIC HERE
            }
     
            #region Constants
     
            private const string ProductsViewItemListTemplateName =
                "Telerik.Samples.Products.Resources.ControlTemplates.Frontend.Modes.ListPageMaster.ascx";
            private string itemListTemplateName;
     
            #endregion
     
     
        }
    }

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Gema
    Gema avatar
    46 posts
    Registered:
    02 Oct 2009
    11 Dec 2009
    Link to this post
    Hi Ivan,
    If my custom module is not based in generic content, is your code still valid to me?
    I don´t store products in sitefinity datatables, but in a specific datatable. So I don´t work with metakeys.

    Thanks
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    11 Dec 2009
    Link to this post
    Hi mgrp,

    In this case you need to inherit from SimpleControl or Composite control and implement your own logic for filtering the items based on a criteria.


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 0 answered