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

Forums / General Discussions / How to create a CustomField for News?

How to create a CustomField for News?

8 posts, 0 answered
  1. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    13 Apr 2011
    Link to this post
    I am trying the following:

    using Telerik.Sitefinity.Configuration;
    using Telerik.Sitefinity.Web.UI;
    using Telerik.Sitefinity.Web.UI.Fields.Config;
    using Telerik.Sitefinity.Web.UI.Fields.Definitions;
     
    namespace QUAY.Sitefinity.Modules
    {
        public class ThumbFieldElementDefinition : TextFieldDefinition
        {
            public ThumbFieldElementDefinition() : base() { }
            public ThumbFieldElementDefinition(ConfigElement element) : base(element) { }
        }
     
        public class ThumbFieldElement : TextFieldDefinitionElement
        {
            public ThumbFieldElement(ConfigElement parent) : base(parent) { }
     
            public override DefinitionBase GetDefinition()
            {
                return new ThumbFieldElementDefinition(this);
            }
        }
    }

    And my control (CustomControl is a class that inhehits from CompositeControl)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.UI.WebControls;
    using QUAY.Web.UI;
    using Telerik.Sitefinity.Web.UI;
    using Telerik.Sitefinity.Web.UI.Fields;
    using Telerik.Sitefinity.Web.UI.Fields.Enums;
    using Telerik.Web.UI;
    using Telerik.Sitefinity.Web.UI.Fields.Contracts;
    using Telerik.Sitefinity.Web.UI.Extenders.Definitions;
     
    namespace QUAY.Sitefinity.Modules
    {
        [FieldDefinitionElement(typeof(ThumbFieldElement))]
        public class ThumbField : CustomControl, IField
        {
            private Label titleLabel;
            private TextBox textBox;
            private HyperLink selectLink;
     
     
            #region IField Members
     
            public void Configure(IFieldDefinition definition)
            {
                //ITextFieldDefinition definition2 = definition as ITextFieldDefinition;
                //if (definition2 != null)
                //{
                //    ExpandableControlDefinition definition3 = new ExpandableControlDefinition();
                //    definition3.ControlDefinitionName = definition2.ControlDefinitionName;
                //    definition3.ViewName = definition2.ViewName;
                //    definition3.SectionName = definition2.SectionName;
                //    definition3.FieldName = definition2.FieldName;
                //    definition3.Expanded = definition2.ExpandableDefinition.Expanded;
                //    //this.ExpandableControlDefinition = definition3;
                //    //this.Expanded = definition2.ExpandableDefinition.Expanded;
                //    //this.Rows = definition2.Rows;
                //    //this.value = definition2.Value;
                //    //this.Value = definition2.Value;
                //    //this.HideIfValue = definition2.HideIfValue;
                //}
            }
     
            public string Description
            {
                get
                {
                    return "Image";
                }
                set
                {
                }
            }
     
            public string Example
            {
                get
                {
                    return "Image";
                }
                set
                {
                }
            }
     
            public string ResourceClassId
            {
                get
                {
                    return "Image";
                }
                set
                {
                }
            }
     
            public string Title
            {
                get
                {
                    return "Image";
                }
                set
                {
                }
            }
     
            #endregion
        }
    }


    I've create a custom field with the type:
    QUAY.Sitefinity.Modules.ThumbField, QUAY.Sitefinity.Modules

    It does work, I can see the control, the control works perfectly except that:
    - All other fields in the news comes in blank.

    Removing the custom fields restores everything back to normal. Why my control doesn't work? And how can I retrieve the Value saved on this field?

    
    
    
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Apr 2011
    Link to this post
    Hi Bruno,

    You can take a look at this post

    http://www.sitefinity.com/blogs/slavoingilizov/posts/11-02-11/creating_a_thumbnail_selector_for_news_items.aspx

    Kind regards,
    Ivan Dimitrov
    the Telerik team

  3. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    14 Apr 2011
    Link to this post
    I am getting errors with that sample which prevents me from saving the news.

    This control I made works, but I get all fields empty. What if I didn't want a image selector but a custom field selector? How could I make it?

    ---

    Inheriting from TextField and overriding the controls and InitializeControls is even worse. The entire page bugs and no value is retrieved on the other fields.

    http://i.imgur.com/g2Uwz.png

    ...........

    http://i.imgur.com/fn3we.png
  4. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    15 Apr 2011
    Link to this post
    If anyone run on this problem be sure to:

    Put the assembly info of your website to SitefinityWebApp because somewhere in Telerek's it is hard coded.
  5. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    28 Apr 2011
    Link to this post
    hi,

    in 4.1 i keep getting the attached image whenever i click 'Back to News' without
    editing the news article at all. using IE8.

    thanks,
    andrei 
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    28 Apr 2011
    Link to this post
    Hello Andrei,

    "Back to News" is shown when you get an item for editing, so you mean that you are not editing the item fields/content? I am not able to replicate this issue with IE8. Are there issues with FF or Chrome?

    Best wishes,
    Ivan Dimitrov
    the Telerik team

  7. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    28 Apr 2011
    Link to this post
    no, no issues in FF or Chrome. in IE8 however i found out that it does it only on a particular news item not on the others.
    this 4.1 is behaving in some of the most strange ways. i guess i will have to delete that news item now???

    andrei
  8. Gary
    Gary avatar
    7 posts
    Registered:
    22 Dec 2010
    11 Jul 2012
    Link to this post
    Did you ever get this to work? I'm having the same problem with a DropDownList I added to the "basic" profile type. The label for the control is blank too.

    Any help is appreciated,
    Thanks,
    Gary
8 posts, 0 answered