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

Forums / General Discussions / How to add custom fields for Posts

How to add custom fields for Posts

9 posts, 0 answered
  1. Shalaka
    Shalaka avatar
    50 posts
    Registered:
    24 Mar 2011
    24 Mar 2011
    Link to this post
    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.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    24 Mar 2011
    Link to this post
    Hi Shalaka,

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

    http://www.sitefinity.com/devnet/forums/sitefinity-4-x/general-discussions/unable-to-add-user-control.aspx

    Kind regards,
    Ivan Dimitrov
    the Telerik team
  3. Shalaka
    Shalaka avatar
    50 posts
    Registered:
    24 Mar 2011
    24 Mar 2011
    Link to this post
    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.

  4. Shalaka
    Shalaka avatar
    50 posts
    Registered:
    24 Mar 2011
    28 Mar 2011
    Link to this post
    Please provide the solution.
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    28 Mar 2011
    Link to this post
    Hi Shalaka,

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

    Please check this post.

    Regards,
    Ivan Dimitrov
    the Telerik team
  6. Shalaka
    Shalaka avatar
    50 posts
    Registered:
    24 Mar 2011
    01 Apr 2011
    Link to this post
    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.

  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    01 Apr 2011
    Link to this post
    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
  8. Shalaka
    Shalaka avatar
    50 posts
    Registered:
    24 Mar 2011
    08 Apr 2011
    Link to this post
    Thanks
    But still i am not able to do this.
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    08 Apr 2011
    Link to this post
    Hi Shalaka,

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

    Regards,
    Ivan Dimitrov
    the Telerik team

9 posts, 0 answered