+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Products Module Single View problem

Products Module Single View problem

2 posts, 1 answered
  1. Sergio
    Sergio avatar
    21 posts
    Registered:
    02 Feb 2009
    07 Sep 2009
    Link to this post
    Dear Sirs,
    using the Product Module,
    we are trying to add some new controls to the ContentViewSingleItem template (we have set this from admin in ProductsPublicView control SingleItemTemplatePath property).
    Overriding  SetItemMetadata method (ProductsPublicView.cs in Telerik.Samples.Products project) to assign some properties to this new controls,
    we cannot get a reference to them (defined in ContentViewSingleItem.ascx template).
    For instance,
    the "imgThumb" control is in the ContentViewItemList.ascx template and works great.
    But the same control inside ContentViewSingleItem.ascx references to null.

     

            protected override void SetItemMetadata(System.Web.UI.Control itemContainer, Telerik.Cms.Engine.IContent contentItem)  
            {  
                base.SetItemMetadata(itemContainer, contentItem);  
                  
                //product thumb  
                Image img = itemContainer.FindControl("imgThumb") as Image;  
                if (img != null)  
                {  
                    string product = contentItem.GetMetaData("Name").ToString();  
                    Libraries.ILibrary lib = GetLibrary(product);   
                    if (lib != null)  
                    {  
                        //System.Collections.IList images = LibManager.GetImages(0, 1, string.Empty, new Guid[] { lib.ID });  
                        if (lib.ItemsCount > 0)  
                        {  
                            IContent libImg = (IContent)lib.GetItems()[0];  
                            img.ImageUrl = libImg.ThumbnailUrl +  
                                "?width=70&height=70&decreaseOnly=true";  
                        }  
                    }  
                }  
            }  
     


    How can we get a reference to our controls from the single view template?
    Thank you very much in advance.
    Best Regards.

  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    07 Sep 2009
    Link to this post
    Hello Sergio,

    Thank you for using our services.

    Can you please try the following iterative search for the control? If this does not work would you be so kind to provide the template markup so that we can better see where is the imgThumb control located (inside which tags)?

     foreach (Control item in itemContainer.Controls) 
         if( item.ID=="imgThumb"
         { img = item as Image; break; } 
         if (item.FindControl("imgThumb") != null
         { img = item.FindControl("imgThumb"as Image; break; } 

    Additionally you could try using Controls collection. The best way is creating a new container for your controls and then use them.

    All the best,
    Radoslav Georgiev
    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.
    Answered
2 posts, 1 answered