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

Forums / Developing with Sitefinity / add property to custom ditributable newsview

add property to custom ditributable newsview

8 posts, 0 answered
  1. Mart
    Mart avatar
    66 posts
    Registered:
    10 Aug 2006
    02 Nov 2009
    Link to this post
    Hello,

    I 've buil a new custom distributable control that inherits from newsview.
    In the templates I use for it there is a new literal for defining the headertitle.
    Now I try to set a public property to set the text in the headertitle but I do not know how to achieve this.

    please help,

    Mart
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    02 Nov 2009
    Link to this post
    Hi Mart,

    In your custom template create a new view state property. Then find the ITextControl from your template and set it as the value from the view state property.

    public string HeadLine
        {
            get
            {
                string headline = (string)ViewState["headline"];
                if (string.IsNullOrEmpty(headline))
                    return "common headline";
                return headline;
            }
            set { this.ViewState["headline"] = value; }
        }
     
     
    ....
       ....
         this.MyLabel.Text = HeadLine;

    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. Mart
    Mart avatar
    66 posts
    Registered:
    10 Aug 2006
    02 Nov 2009
    Link to this post
    Hello Ivan,

    This is my code but it does give an error

    using

     

    System;

     

     

    using

     

    System.Collections.Generic;

     

     

    using

     

    System.ComponentModel;

     

     

    using

     

    System.Linq;

     

     

    using

     

    System.Text;

     

     

    using

     

    System.Web.UI.HtmlControls;

     

     

    using

     

    System.Web.UI.WebControls;

     

     

    using

     

    Telerik.Framework.Web;

     

     

    using

     

    Telerik.Cms.Web;

     

     

    using

     

    Telerik.Framework.Web.Design;

     

     

    using

     

    System.Web.UI;

     

     

    using

     

    Telerik.News.WebControls;

     

     

    using

     

    Telerik.Cms.Web.UI;

     

     

    using

     

    Telerik.Web;

     

     

     

    namespace

     

    ArtisteerAddon

     

    {

     

     

     

    public class News : NewsView

     

     

    {

     

     

    #region

     

    layout properties

     

     

     

    /// <summary>

     

     

     

    /// Used for loading controls from a template (defines the layout)

     

     

     

    /// </summary>

     

     

    [

    Browsable(false)]

     

     

     

    protected virtual GenericContainer Container

     

    {

     

     

    get

     

     

    {

     

    if (this.container == null)

     

    {

     

     

    this.container = new GenericContainer();

     

     

     

    if (this.LayoutTemplate != null)

     

    {

     

     

    this.LayoutTemplate.InstantiateIn(this.container);

     

    }

    }

     

     

    return this.container;

     

    }

    }

     

     

    /// <summary>

     

     

     

    /// Gets or sets the template defining the layout of the control.

     

     

     

    /// </summary>

     

     

    [

    TemplateContainer(typeof(GenericContainer))]

     

    [

     

    PersistenceMode(PersistenceMode.InnerProperty)]

     

    [

     

    Description("Gets or sets the template defining the layout of the control.")]

     

    [

     

    Browsable(false)]

     

    [

     

    DefaultValue(typeof(ITemplate), "")]

     

     

     

    public virtual ITemplate LayoutTemplate

     

    {

     

     

    get

     

     

    {

     

    if (this.layoutTemplate == null)

     

    {

     

     

    this.layoutTemplate = ControlUtils.GetTemplate(this.LayoutTemplatePath,

     

     

     

    this.ItemListTemplateName, this.GetType());

     

    }

     

     

    return this.layoutTemplate;

     

    }

     

     

    set

     

     

    {

     

    this.layoutTemplate = value;

     

    }

    }

     

     

    /// <summary>

     

     

     

    /// Gets or sets the path to a custom layout template for the control.

     

     

     

    /// </summary>

     

     

    [

    Browsable(true)]

     

    [

     

    Category("Appearance")]

     

    [

     

    Description("Gets or sets the path to a custom layout template for the control.")]

     

    [

     

    EmbeddedTemplate(News.NewsViewCustomItemListTemplateName, "Layout template path for newsview", "/Templates/", true, "2009/3/31")]

     

     

     

    public virtual string LayoutTemplatePath

     

    {

     

     

    get

     

     

    {

     

    object persistedValue = this.ViewState["LayoutTemplatePath"];

     

     

     

    if (persistedValue != null)

     

    {

     

     

    return (string)persistedValue;

     

    }

     

     

    else

     

     

    {

     

    return String.Empty;

     

    }

    }

     

     

    set

     

     

    {

     

    this.ViewState["LayoutTemplatePath"] = value;

     

    }

    }

     





     

    #endregion

     

    public override string ItemListTemplateName

     

    {

     

     

    get

     

     

    {

     

    return News.NewsViewCustomItemListTemplateName;

     

    }

    }

     

     

    /// <summary>

     

     

     

    /// Gets the name of the embedded layout template. If the control uses layout template

     

     

     

    /// this property must be overridden to provide the path (key) to an embedded resource file.

     

     

     

    /// </summary>

     

     

     

    /// <value></value>

     

     

     

    public override string SingleItemTemplateName

     

    {

     

     

    get

     

     

    {

     

    return News.NewsViewCustomSingleItemTemplateName;

     

    }

    }

     

     

    public override Type AssemblyInfo

     

    {

     

     

    get

     

     

    {

     

    return typeof(News);

     

    }

     

     

    set

     

     

    {

     

    base.AssemblyInfo = value;

     

    }

    }



     

     

    #region

     

    properties

     

     

     

    /// <summary>

     

     

     

    /// The text of the title above the content area

     

     

     

    /// </summary>

     

     

    [

    Browsable(true)]

     

    [

     

    Category("Appearance")]

     

    [

     

    Description("The text of the header")]

     

    [

     

    TypeConverter(typeof(StringConverter))]

     

     

     

    public string HeaderTitle

     

    {

     

     

    get { return this.HeaderTitleText.Text; }

     

     

     

    set { this.HeaderTitleText.Text = value; }

     

    }

     

     

     



     

    #endregion

     

    #region

     

    control references

     

     

     

    /// <summary>

     

     

     

    /// The title above the content

     

     

     

    /// </summary>

     

     

    [

    Browsable(false)]

     

     

     

    public ITextControl HeaderTitleText

     

    {

     

     

    get { return this.Container.GetControl<ITextControl>("headertitle", true); }

     

    }

     

    #endregion

     

    #region

     

    Constants

     



     

     

    //private const string NewsViewCustomItemListTemplateName = "ArtisteerAddon.Resources.Templates.News.ListPageMaster.ascx";

     

     

     

    public const string NewsViewCustomItemListTemplateName = "ArtisteerAddon.Resources.Templates.News.ListPageMaster.ascx";

     

     

     

    private const string NewsViewCustomSingleItemTemplateName = "ArtisteerAddon.Resources.Templates.News.ListPageDetails.ascx";

     

     

     

    #endregion



    #region

     

    fields

     

     

     

    /// <summary>

     

     

     

    /// Holds the value of the LayoutTemplate property

     

     

     

    /// </summary>

     

     

     

    private ITemplate layoutTemplate;

     

     

     

     

    /// <summary>

     

     

     

    /// Holds the value of the Container property

     

     

     

    /// </summary>

     

     

     

    private GenericContainer container;

     

     

    #endregion

    }

    }

     


    This is the error:

    De objectverwijzing is niet op een exemplaar van een object ingesteld.

    Beschrijving: Er is een onverwerkte uitzondering opgetreden tijdens het uitvoeren van de huidige webaanvraag. Raadpleeg de stacktracering voor meer informatie over deze fout en de oorsprong ervan in de code.

    Details van uitzondering: System.NullReferenceException: De objectverwijzing is niet op een exemplaar van een object ingesteld.

    Fout in bron:

    Regel 38: if (this.LayoutTemplate != null) Regel 39: 
    { Regel 40: this.LayoutTemplate.InstantiateIn(this.container); Regel 41: }
    Regel 42:

  4. Mart
    Mart avatar
    66 posts
    Registered:
    10 Aug 2006
    03 Nov 2009
    Link to this post
    Hello,

    do you have a solution for this problem?
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    03 Nov 2009
    Link to this post
    Hello Mart,

    The error comes from the container or the template you use. One of them is null. The error  is not caused by the property.

    Greetings,
    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.
  6. Mart
    Mart avatar
    66 posts
    Registered:
    10 Aug 2006
    03 Nov 2009
    Link to this post
    Ivan,

    Thanks, for your answer. But I can not find the problem with it.

    My template code is:

    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="sf" %> 
     
     
    <sf:CssFileLink ID="CssFileLink1" EmbeddedFileName="ArtisteerAddon.Resources.Styles.newscommonlayout.css" 
        Media="screen" runat="server" /> 
    <sf:JsFileLink ID="jQueryLink" runat="server" FileName="~/Scripts/jquery.js" />      
     
     
     
          
     
     
          
         
          
     
     <div class="art-Block">  
                                <div class="art-Block-tl"></div> 
                                <div class="art-Block-tr"></div> 
                                <div class="art-Block-bl"></div> 
                                <div class="art-Block-br"></div> 
                                <div class="art-Block-tc"></div> 
                                <div class="art-Block-bc"></div> 
                                <div class="art-Block-cl"></div> 
                                <div class="art-Block-cr"></div> 
                                <div class="art-Block-cc"></div> 
                                <div class="art-Block-body">  
                                            <div class="art-BlockHeader">  
                                                <div class="l"></div> 
                                                <div class="r"></div> 
                                                <div class="art-header-tag-icon">  
                                                    <div class="t"><asp:Literal ID="headertitle" runat="server" Text="nieuws"  /></div>  
                                                </div> 
                                            </div> 
                                            <div class="art-BlockContent">  
                                                <div class="art-BlockContent-body">  
                                              
    <div> 
    <asp:HyperLink ID="backLink" runat="server" Text="<%$Resources:GoBack %>"></asp:HyperLink> 
    <asp:Repeater ID="repeater" runat="server">  
        <HeaderTemplate> 
            <ul class="sf_newsList">  
        </HeaderTemplate> 
        <ItemTemplate> 
              
              <h4 class="sf_newsDate">  
                        <sf:DateTimeLiteral ID="Publication_Date" runat="server" DateFormatString="dd MMMM yyyy" />    
              </h4>    
              </br>    
                <div class="sf_newsBody" > 
                      
                    <class="sf_newsTitle">  
                    <asp:HyperLink ID="fullContent1" runat="server" > 
                        <asp:Literal ID="Title" runat="server"></asp:Literal> 
                    </asp:HyperLink> 
                    </p> 
                    <class="sf_newsSummary" > 
                        <asp:Literal ID="Summary" runat="server" Text=""></asp:Literal> 
                    </p> 
                    <class="sf_readMore">  
                        <asp:HyperLink ID="fullContent2" runat="server">  
                            <asp:Literal ID="LiteralFS" runat="server" Text="<%$Resources:FullStory %>"></asp:Literal> 
                        </asp:HyperLink> 
                    </p> 
                    </br> 
                      
                    <asp:PlaceHolder ID="ThumbnailHolder" runat="server">  
                        <class="sf_newsThumbnail">  
                            <asp:Image ID="Thumbnail" runat="server" /></p>  
                    </asp:PlaceHolder> 
                    <class="sf_newsAuthor">  
                        <asp:Literal ID="Author" runat="server"></asp:Literal> 
                    </p> 
                    <p> 
                        <asp:Literal ID="Source" runat="server"></asp:Literal> 
                    </p> 
                    <class="sf_postCategory">  
                        <asp:HyperLink ID="Category" runat="server" /> 
                    </p> 
                    <class="sf_postTags">  
                        <asp:Repeater ID="Tags" runat="server">  
                            <ItemTemplate> 
                                <asp:HyperLink ID="tagLink" runat="server" /> 
                            </ItemTemplate> 
                        </asp:Repeater> 
                    </p> 
                </div> 
             
        </ItemTemplate> 
        <FooterTemplate> 
            </ul> 
        </FooterTemplate> 
    </asp:Repeater> 
    <sf:Pager ID="pager1" runat="server">  
        <LayoutTemplate> 
            <asp:Repeater ID="PageRepeaterLinkButton" runat="server">  
                <HeaderTemplate> 
                    <ol class="sf_pager">  
                        <li> 
                            <asp:LinkButton ID="PreviousPage" runat="server" Text="<%$Resources:PreviousPage %>"></asp:LinkButton></li>  
                </HeaderTemplate> 
                <ItemTemplate> 
                    <li> 
                        <asp:LinkButton ID="SingleItem" runat="server" /> 
                    </li> 
                </ItemTemplate> 
                <FooterTemplate> 
                    <li> 
                        <asp:LinkButton ID="NextPage" runat="server" Text="<%$Resources:NextPage %>"></asp:LinkButton></li>  
                    </ol> 
                </FooterTemplate> 
            </asp:Repeater> 
            <asp:Repeater ID="PageRepeaterHyperLink" runat="server">  
                <HeaderTemplate> 
                    <ol class="sf_pager">  
                        <li> 
                            <asp:HyperLink ID="PreviousPage" runat="server" Text="<%$Resources:PreviousPage %>"></asp:HyperLink></li>  
                </HeaderTemplate> 
                <ItemTemplate> 
                    <li> 
                        <asp:HyperLink ID="SingleItem" runat="server" /> 
                    </li> 
                </ItemTemplate> 
                <FooterTemplate> 
                    <li> 
                        <asp:HyperLink ID="NextPage" runat="server" Text="<%$Resources:NextPage %>"></asp:HyperLink></li>  
                    </ol> 
                </FooterTemplate> 
            </asp:Repeater> 
        </LayoutTemplate> 
    </sf:Pager> 
    </div>   
    <div class="cleared"></div> 
                                                </div> 
                                            </div> 
                                    <div class="cleared"></div> 
                                </div> 
                            </div> 
  7. Mart
    Mart avatar
    66 posts
    Registered:
    10 Aug 2006
    03 Nov 2009
    Link to this post
    Please help

    Mart
  8. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    03 Nov 2009
    Link to this post
    Hi Mart,

    Could you please zip up the whole control (project) with all embedded templates so that we can set it up locally and see what is going wrong. To do this please open a new support ticket and attach the ditributable control project in a zip file.

    Thank you for your cooperation in advance.

    Best wishes,
    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.
Register for webinar
8 posts, 0 answered