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

Forums / Developing with Sitefinity / Custom attributes in news view

Custom attributes in news view

5 posts, 1 answered
  1. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    06 Jul 2010
    Link to this post
    Hi,
    I have created a custom view by inheriting Class NewsView. I have added a new attribute to the class called Title. I set the value to the title using the sitefinity drag drop feature and set the value.

    However i am using the SingleItemTemplatePath and ItemListTemplatePath which have the virtual path of the user control created by me. These user control have a literal control insite it which is the place holder for the title.

    How can I set the value of the Literal control from my Custom class. Please explain.

    Also, if is there any other way to implement this.



    Regards,
    Siddesh Kapadi
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    06 Jul 2010
    Link to this post
    Hi Siddesh Kapadi,

    It depends on whether you have added the Literal control. If it is inside the repeater you can access it from SetItemMetadata method where you can use itemContainer.FindControl method.

    When you preview the item in single mode you have to create a control reference and get control by using  SingleContainer<T>()

    public virtual Literal CustomLiteralControl
    {
        get
        {
            return this.SingleContainer.GetControl<Literal>("Litral1", false);
        }
    }


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    07 Jul 2010
    Link to this post
    Hi,
    Below is my custom Code for the ascx Page:
    <asp:Repeater ID="repeater" runat="server"> <HeaderTemplate> <div class="col2"> <h3 class="border"><asp:Literal ID="litHeader" runat="server"></asp:Literal></h3> </HeaderTemplate> <ItemTemplate> <div class="whitepaper"> <p> <asp:Label ID="Source" CssClass="type" runat="server"></asp:Label> <br /> <asp:HyperLink ID="fullContent1" runat="server"> <asp:Literal ID="Title" runat="server"></asp:Literal> </asp:HyperLink> <br /> </p> </div> </ItemTemplate> <FooterTemplate> <p class="graycta"> <a href="#" class="caps arrow">See more news, research &amp; insights</a></p> </div> </FooterTemplate> </asp:Repeater>


    I have a file located in app_code:
    When and how can I access the litHeader Control located in Controls ascx file.

    The above solution still gives me an nullreference exception.

    Please Help!!!!!!!!


    Regards,
    Siddesh Kapadi
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    07 Jul 2010
    Link to this post
    Hello Siddesh Kapadi,

    You can use the control reference below to find the control you have added

    public virtual Literal CustomLiteralControl
     {
         get
         {
             return this.ListContainer.GetControl<Literal>("litHeader", false, Telerik.Framework.Web.TraverseMethod.BreadthFirst);
         }
     }

    Note that you should add the control reference in a custom class that inherits from NewsView

    public class NewsViewCustomControl : NewsView
    {
     
     
        public override string ItemListTemplatePath
        {
            get
            {
                return "~/Sitefinity/ControlTemplates/News/ListPageMaster.ascx";
            }
     
        }
     
        public override string SingleItemTemplatePath
        {
            get
            {
                return "~/Sitefinity/ControlTemplates/News/ListPageDetails.ascx";
            }
     
        }
     
     
        public override Type LocalizationAssemblyInfo
        {
            get
            {
                return this.GetType();
            }
            set
            {
                base.LocalizationAssemblyInfo = value;
            }
        }
     
        public override Type AssemblyInfo
        {
            get
            {
                return this.GetType();
            }
            set
            {
                base.AssemblyInfo = value;
            }
        }
     
      protected override void CreateChildControls()
        {
            base.CreateChildControls();   
     
            if (CustomLiteralControl != null)
            {
                CustomLiteralControl.Text = "Hello";
            }
        }
     
        public virtual Literal CustomLiteralControl
        {
            get
            {
                return this.ListContainer.GetControl<Literal>("litHeader", false, Telerik.Framework.Web.TraverseMethod.BreadthFirst);
            }
        }
     
     
    }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  5. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    07 Jul 2010
    Link to this post
    Hey,
    Thanks. This is the umpteenth time that u have come to my rescue. :)
    Thanks once again.
Register for webinar
5 posts, 1 answered