How to add custom fields for Posts
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.
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
Please provide the solution.
Hi Shalaka,
Ok, you need to create a custom control that inherits from CompositeFieldControl
Please check this post.
Regards,
Ivan Dimitrov
the Telerik team
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
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"
;
<%@ 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"
/>
Thanks
But still i am not able to do this.
Hi Shalaka,
The sample works fine. I am not sure what the problem would be.
Regards,
Ivan Dimitrov
the Telerik team