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

Forums / Developing with Sitefinity / NewsView not binding to Author

NewsView not binding to Author

2 posts, 0 answered
  1. Mike Sharp
    Mike Sharp avatar
    3 posts
    Registered:
    27 May 2009
    25 Mar 2010
    Link to this post

    Hi,
    In the newsview control details rendering template, I've created a user control that implements ITextControl.  This works nicely in that I get the meta field content and can work with it.  But when I put the same user control in the master view, it does not bind the Author meta field to it.

    However, if I add a literal to the master template, with the "Author" ID, it binds fine.

    Apparently, there is a difference between how the news view binds to controls between Master and Details.

    This works:

    <p>
        <asp:Literal ID="Summary" runat="server" Text=""></asp:Literal>
    </p>
    <asp:Literal ID="Author" runat="server" />

    This does not:
    <p>
        <asp:Literal ID="Summary" runat="server" Text=""></asp:Literal>
    </p>
    <iv:NewsAuthor ID="Author" runat="server" />

    My NewsAuthor control correctly implements ITextControl, because this same code works fine in the Details template.

    I thought about creating a new NewsView control that inherits the Sitefinity one, but I can't figure out how to find my custom control in the SetItemMetadata method, and set it's Text property.

    Regards,
    Mike Sharp
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    26 Mar 2010
    Link to this post
    Hi Mike Sharp,

    Here is a code sample that illustrates how to find a custom control inside your master and detail template

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.News.WebControls;
    using System.Web.UI.WebControls;
     
    /// <summary>
    /// Summary description for NewsViewCustomControl
    /// </summary>
    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";
            }
     
        }
     
        protected override void SetItemMetadata(System.Web.UI.Control itemContainer, Telerik.Cms.Engine.IContent contentItem)
        {
            base.SetItemMetadata(itemContainer, contentItem);
                // find the control from the list
            var someControl = itemContainer.FindControl("Litral1") as Literal;
            if (someControl != null)
            {
                someControl.Text = "HelloThere this is text for items in the list";
            }
            if (CustomLiteralControl != null)
            {
                CustomLiteralControl.Text = "helloThere";
            }
        }
        
     
        //HERE I USE LITERAL, BUT YOU WILL BE ABLE TO FIND YOUR CUSTOM CONTROL IN THE SAME WAY
        public virtual Literal CustomLiteralControl
        {
            get
            {
                return this.SingleContainer.GetControl<Literal>("Litral1", false);
            }
        }
     
     
    }

    ListPageMaster

    %@ Control Language="C#" %>
     
    <telerik:CssFileLink ID="CssFileLink1" EmbeddedFileName="Telerik.News.Resources.ControlTemplates.Frontend.newsCommonLayout.css" FileName="" Media="screen" runat="server" />
     
    <asp:HyperLink ID="backLink" runat="server" Text="<%$Resources:GoBack %>"></asp:HyperLink>
    <asp:Repeater ID="repeater" runat="server">
        <HeaderTemplate>
            <ul class="sf_newsList">
        </HeaderTemplate>
        <ItemTemplate>
            <li>
             
                <h2 class="sf_newsTitle">
                    <asp:HyperLink ID="fullContent1" runat="server">
                        <asp:Literal ID="Title" runat="server"></asp:Literal>
                    </asp:HyperLink>
                    <asp:Literal runat="server" ID="Litral1"/>
                </h2>
                <p class="sf_newsDate">
                    <asp:Literal ID="Publication_Date" runat="server" Text="{0}" />
                </p>
                <p>
     
     
                  .....
                         .....

    ListPageDetail

    <%@ Control Language="C#" %>
    <%@ Register Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls" TagPrefix="sfWeb" %>
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Web.UI.SpamProtection" TagPrefix="sfWeb" %>
     
    <telerik:CssFileLink ID="CssFileLink1" EmbeddedFileName="Telerik.News.Resources.ControlTemplates.Frontend.newsCommonLayout.css" FileName="" Media="screen" runat="server" />
    <telerik:JsFileLink id="jsLink" runat="server" ScriptType="jQuery" />
         
    <div class="sf_singleNews">
        <asp:HyperLink ID="backToList1" Text="<%$Resources:AllNews %>" CssClass="sf_back" runat="server"></asp:HyperLink>
         
            <asp:Literal runat="server" ID="Litral1"/>
        <h2 class="sf_NewsTitle">
            <asp:Literal ID="Title" runat="server"></asp:Literal>
        </h2>
        <p class="sf_newsDate">
            <asp:Literal ID="Publication_Date" runat="server" Text="{0}" />
        </p>
        <p>
     
                       ....
                              ....

    I use literal, but you can use any other control in the same way.

    Greetings,
    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.
2 posts, 0 answered