How to add custom fields for Posts

Posted by Community Admin on 03-Aug-2018 12:30

How to add custom fields for Posts

All Replies

Posted by Community Admin on 24-Mar-2011 00:00

I am trying to add one user control as custom field to Posts , but getting following error
"Type "ASP.usercontrols_webusercontrol2_ascx" cannot be resolved."
'Add a Field' section i am selecting Type = 'ShortText' as Type , Interface widget for entering data = Custom,
and entering ~/UserControls/webusercontrol2_ascx as the virtual path.
I want to add a combo box to the Posts.

Posted by Community Admin on 24-Mar-2011 00:00

Hi Shalaka,

Please check this post that shows how to register a custom widget

www.sitefinity.com/.../unable-to-add-user-control.aspx

Kind regards,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 24-Mar-2011 00:00

Hi,
Thanks.
But this is not the solution for me.
I want to add a custom field to my Blog->Posts.
In BLOG , On LHS there is a option for  Custom Fields for posts  under Settings For Blogs.
From that i want to add to add custom field.

Posted by Community Admin on 28-Mar-2011 00:00

Please provide the solution.

Posted by Community Admin on 28-Mar-2011 00:00

Hi Shalaka,

Ok, you need to create a custom control that inherits from CompositeFieldControl

Please check this post.

Regards,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 01-Apr-2011 00:00

Hi,
Still i am not able to do this.
Please can you provide me demo - for adding simple text box of visual studio to my Blogs-Post.

Actually

 I want to add one combo box in my Blogs-Posts page. The combo box should show list of ‘Authors’ from table-‘AuthorMaster’.
I tried doing the same by creating a usercontrol , but it is not happening.
I searched and found that custom control is feasible by implementing CompositeFieldControl class.
But still i am not able to do that.

Posted by Community Admin on 01-Apr-2011 00:00

Hello Shalaka,


The easiest way here is creating a custom control that inherits directly from ChoiceField

namespace Telerik.Sitefinity.Samples
    public class ChoiceFieldCustom : ChoiceField
    
        public ChoiseFieldCustom()
        
            this.RenderChoicesAs = Sitefinity.Web.UI.Fields.Enums.RenderChoicesAs.DropDown;
        
  
        protected override void CreateChildControls()
        
  
            for (int i = 0; i < 5; i++)
            
                    ChoiceItem ci = new ChoiceItem()
                    
                        Text = "item" + i,
                        Value = i.ToString(),
                    ;
                    this.Choices.Add(ci);
                  
            
  
            base.CreateChildControls();
          
  
        
  
        protected override string LayoutTemplateName
        
            get
            
                return ChoiseFieldCustom.layoutTempalte;
            
        
  
  
  
        public override IEnumerable<System.Web.UI.ScriptDescriptor> GetScriptDescriptors()
        
            var descriptors = base.GetScriptDescriptors();
  
            var descriptor = (ScriptControlDescriptor)descriptors.Last();
            descriptor.Type = typeof(ChoiceField).FullName;
  
            return descriptors;
        
  
        private const string layoutTempalte = "Telerik.Sitefinity.Samples.Resources.ChoiceField.ascx";
  
    

Inside the constructur you should set the mode to DropDown.

<%@ Control Language="C#" %>
  
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %>
  
<sf:ConditionalTemplateContainer ID="conditionalTemplate" runat="server">
    <Templates>
        <sf:ConditionalTemplate ID="ConditionalTemplate1" Left="DisplayMode" Operator="Equal" Right="Read" runat="server">
            <sf:SitefinityLabel id="titleLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfTxtLbl" />
            <sf:SitefinityLabel id="read" runat="server" WrapperTagName="div" HideIfNoText="false" />
        </sf:ConditionalTemplate>
        <sf:ConditionalTemplate ID="ConditionalTemplate2" Left="RenderChoicesAs" Operator="Equal" Right="CheckBoxes" runat="server">
            <sf:SitefinityLabel id="titleLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfTxtLbl" />
            <asp:CheckBoxList ID="checkBoxes" runat="server" RepeatLayout="Flow" CssClass="sfCheckListBox sfFieldWrp"></asp:CheckBoxList>
        </sf:ConditionalTemplate>
        <sf:ConditionalTemplate ID="ConditionalTemplate3" Left="RenderChoicesAs" Operator="Equal" Right="DropDown" runat="server">
            <asp:Label ID="titleLabel" runat="server" CssClass="sfTxtLbl" AssociatedControlID="dropDown"></asp:Label>
            <span class="sfDropdownList sfFieldWrp"><asp:DropDownList ID="dropDown" runat="server"></asp:DropDownList></span>
        </sf:ConditionalTemplate>
        <sf:ConditionalTemplate ID="ConditionalTemplate4" Left="RenderChoicesAs" Operator="Equal" Right="ListBox" runat="server">
            <asp:Label ID="titleLabel" runat="server" CssClass="sfTxtLbl" AssociatedControlID="listBox"></asp:Label>
            <asp:ListBox ID="listBox" runat="server"></asp:ListBox>
        </sf:ConditionalTemplate>
        <sf:ConditionalTemplate ID="ConditionalTemplate5" Left="RenderChoicesAs" Operator="Equal" Right="RadioButtons" runat="server">
            <sf:SitefinityLabel id="titleLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfTxtLbl" />
            <asp:RadioButtonList ID="radioButtons" runat="server"
                                 RepeatLayout="Flow"
                                 RepeatDirection="Vertical"
                                 CssClass="sfRadioList sfFieldWrp">
            </asp:RadioButtonList>
        </sf:ConditionalTemplate>
        <sf:ConditionalTemplate ID="ConditionalTemplate6" Left="RenderChoicesAs" Operator="Equal" Right="HorizontalRadioButtons" runat="server">
            <sf:SitefinityLabel id="titleLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfTxtLbl" />
            <asp:RadioButtonList ID="radioButtons" runat="server"
                                 RepeatLayout="Flow"
                                 RepeatDirection="Horizontal"
                                 CssClass="sfRadioList sfFieldWrp">
            </asp:RadioButtonList>
        </sf:ConditionalTemplate>
        <sf:ConditionalTemplate ID="ConditionalTemplate7" Left="RenderChoicesAs" Operator="Equal" Right="SingleCheckBox" runat="server">
            <sf:SitefinityLabel id="titleLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfTxtLbl" />
            <asp:CheckBox ID="singleCheckBox" runat="server" />
        </sf:ConditionalTemplate>
    </Templates>      
</sf:ConditionalTemplateContainer>
<sf:SitefinityLabel id="descriptionLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfDescription" />
<sf:SitefinityLabel id="exampleLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfExample" />


All the best,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 08-Apr-2011 00:00

Thanks
But still i am not able to do this.

Posted by Community Admin on 08-Apr-2011 00:00

Hi Shalaka,

The sample works fine. I am not sure what the problem would be.

Regards,
Ivan Dimitrov
the Telerik team


This thread is closed