Error in Custom Fields in 4.1

Posted by Community Admin on 03-Aug-2018 21:28

Error in Custom Fields in 4.1

All Replies

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

Next problem...

I have custom field controls as described in this post and this post.  I've upgraded to 4.1 but am getting the following error when trying to hit my content page in the backend:

A required control was not found in the template for "~/Content/field_controls/BioSimpleImageField/BioSimpleImageField.ascx". The control must be assignable form type "System.Web.UI.WebControls.TextBox" and must have ID "textBox_write".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
 
Exception Details: Telerik.Sitefinity.Web.UI.TemplateException: A required control was not found in the template for "~/Content/field_controls/BioSimpleImageField/BioSimpleImageField.ascx". The control must be assignable form type "System.Web.UI.WebControls.TextBox" and must have ID "textBox_write".
 
Source Error:
 
 
Line 205:        protected override void InitializeControls(GenericContainer container)
Line 206:       
Line 207:            this.ConstructControl();
Line 208:       
Line 209:

My code:

BioSimpleImageField.ascx
<%@ Control Language="C#" AutoEventWireup="true" %>
 
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sitefinity" %>
<%@ Register Assembly="SitefinityWebApp" Namespace="SitefinityWebApp.Content.FieldControls" TagPrefix="fc" %>
 
<sitefinity:ResourceLinks ID="resourcesLinks" runat="server">
    <sitefinity:ResourceFile JavaScriptLibrary="JQuery">
    </sitefinity:ResourceFile>
</sitefinity:ResourceLinks>
 
<sitefinity:ConditionalTemplateContainer ID="conditionalTemplate" runat="server">
    <Templates>
        <sitefinity:ConditionalTemplate Left="DisplayMode" Operator="Equal" Right="Read">
            <sitefinity:SitefinityLabel id="titleLabelRead" runat="server" WrapperTagName="div" HideIfNoText="false" CssClass="sfTxtLbl"></sitefinity:SitefinityLabel>
            <sitefinity:SitefinityLabel id="textLabelRead" runat="server" WrapperTagName="div" HideIfNoText="false" CssClass="sfTxtContent"></sitefinity:SitefinityLabel>
            <asp:Image ID="image" runat="server" />
            <sitefinity:SitefinityLabel id="descriptionLabelRead" runat="server" WrapperTagName="p" HideIfNoText="false" CssClass="sfDescription"></sitefinity:SitefinityLabel>
            <sitefinity:SitefinityLabel id="exampleLabelRead" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfExample" />
        </sitefinity:ConditionalTemplate>
        <sitefinity:ConditionalTemplate Left="DisplayMode" Operator="Equal" Right="Write">
            <sitefinity:SitefinityLabel ID="titleLabelWrite" runat="server" CssClass="sfTxtLbl" />
            <asp:LinkButton ID="expandButton" runat="server" OnClientClick="return false;" CssClass="sfOptionalExpander" />
            <asp:Panel ID="expandableTarget" runat="server" CssClass="sfFieldWrp">
 
                <telerik:RadWindowManager ID="windowManager" runat="server" Skin="Sitefinity">
                    <Windows>
                        <telerik:RadWindow ID="BioSimpleImageSelector" Width="600" Height="400" NavigateUrl="~/Sitefinity/Dialog/BioSimpleImageSelectorDialog" runat="server" ReloadOnShow="true"
                         Modal="true" VisibleStatusbar="false" Behaviors="Close" >
                        </telerik:RadWindow>
                    </Windows>
                </telerik:RadWindowManager>
 
                <asp:TextBox ID="textBox" runat="server" CssClass="sfTxt" />
                <asp:HyperLink ID="selectLink" runat="server" NavigateUrl="javascript:void(0);" CssClass="sfLinkBtn sfChange">
                    <strong class="sfLinkBtnIn">Select...</strong>
                </asp:HyperLink>
                <sitefinity:SitefinityLabel id="descriptionLabelWrite" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfDescription" />
                <sitefinity:SitefinityLabel id="exampleLabelWrite" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfExample" />
                 
            </asp:Panel>
        </sitefinity:ConditionalTemplate>
    </Templates>
</sitefinity:ConditionalTemplateContainer>

BioSimpleImageField.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Web.UI;
using Telerik.Sitefinity.Web.UI.Fields;
using Telerik.Sitefinity.Web.UI.Fields.Enums;
using Telerik.Web.UI;
 
namespace SitefinityWebApp.Content.FieldControls
    /// <summary>
    /// A simple field control used to select a thumbnail from a Sitefinity library.
    /// </summary>
    [FieldDefinitionElement(typeof(BioSimpleImageFieldElement))]
    public class BioSimpleImageField : TextField
    
        #region Properties
         
        /// <summary>
        /// Gets the name of the layout template.
        /// </summary>
        /// <value>The name of the layout template.</value>
        protected override string LayoutTemplateName
        
            get
            
                return String.Empty;
            
        
 
        /// <summary>
        /// Gets or sets the layout template path.
        /// </summary>
        /// <value>The layout template path.</value>
        public override string LayoutTemplatePath
        
            get
            
                return "~/Content/field_controls/BioSimpleImageField/BioSimpleImageField.ascx";
            
            set
            
                base.LayoutTemplatePath = value;
            
        
 
        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>The value.</value>
        public override object Value
        
            get
            
                var val = string.Empty;
                switch (this.DisplayMode)
                
                    case FieldDisplayMode.Read:
                        val = this.ImageControl.ImageUrl;
                        break;
                    case FieldDisplayMode.Write:
                        val = this.TextBoxControl.Text;
                        break;
                
                return val;
            
            set
            
                if (this.ChildControlsCreated)
                
                    switch (this.DisplayMode)
                    
                        case FieldDisplayMode.Write:
                            this.TextBoxControl.Text = value as string;
                            break;
 
                        case FieldDisplayMode.Read:
                            this.ImageControl.ImageUrl = value as string;
                            break;
                    
                    base.Value = null;
                
                else
                
                    base.Value = value;
                
            
        
 
        /// <summary>
        /// Gets the label control.
        /// </summary>
        /// <value>The label control.</value>
        protected override Label LabelControl
        
            get
            
                return this.Container.GetControl<Label>("textLabelRead", this.DisplayMode == FieldDisplayMode.Read);
            
        
 
        /// <summary>
        /// Gets the title label.
        /// </summary>
        /// <value>The title label.</value>
        protected override Label TitleLabel
        
            get
            
                SitefinityLabel titleLabel = null;
                switch (this.DisplayMode)
                
                    case FieldDisplayMode.Read:
                        titleLabel = this.Container.GetControl<SitefinityLabel>("titleLabelRead", true);
                        break;
                    case FieldDisplayMode.Write:
                        titleLabel = this.Container.GetControl<SitefinityLabel>("titleLabelWrite", true);
                        break;
                
                return titleLabel;
            
        
 
        /// <summary>
        /// Gets the description label.
        /// </summary>
        /// <value>The description label.</value>
        protected override Label DescriptionLabel
        
            get
            
                SitefinityLabel descriptionLabel = null;
                switch (this.DisplayMode)
                
                    case FieldDisplayMode.Read:
                        descriptionLabel = this.Container.GetControl<SitefinityLabel>("descriptionLabelRead", true);
                        break;
                    case FieldDisplayMode.Write:
                        descriptionLabel = this.Container.GetControl<SitefinityLabel>("descriptionLabelWrite", true);
                        break;
                
                return descriptionLabel;
            
        
 
        /// <summary>
        /// Gets the example label.
        /// </summary>
        /// <value>The example label.</value>
        protected override Label ExampleLabel
        
            get
            
                SitefinityLabel exampleLabel = null;
                switch (this.DisplayMode)
                
                    case FieldDisplayMode.Read:
                        exampleLabel = this.Container.GetControl<SitefinityLabel>("exampleLabelRead", true);
                        break;
                    case FieldDisplayMode.Write:
                        exampleLabel = this.Container.GetControl<SitefinityLabel>("exampleLabelWrite", true);
                        break;
                
                return exampleLabel;
            
        
 
        /// <summary>
        /// Gets a reference to the <see cref="Image"/> control used to display the thumbnail in Read mode
        /// </summary>
        protected Image ImageControl
        
            get
            
                return this.Container.GetControl<Image>("image", this.DisplayMode == FieldDisplayMode.Read);
            
        
 
        /// <summary>
        /// Get a reference to the link that opens the simple image selector
        /// </summary>
        protected virtual HyperLink SelectLink
        
            get
            
                return this.Container.GetControl<HyperLink>("selectLink", this.DisplayMode == FieldDisplayMode.Write);
            
        
 
        /// <summary>
        /// Gets a reference to the RadWindowManager
        /// </summary>
        protected virtual RadWindowManager RadWindowManager
        
            get
            
                return this.Container.GetControl<RadWindowManager>("windowManager", true);
            
        
 
        #endregion
 
        protected override void InitializeControls(GenericContainer container)
        
            this.ConstructControl();
        
 
        #region IScriptControl Members
 
        /// <summary>
        /// Gets the script references.
        /// </summary>
        /// <returns></returns>
        public override IEnumerable<ScriptReference> GetScriptReferences()
        
            var baseReferences = new List<ScriptReference>(base.GetScriptReferences());
            var newRef = new ScriptReference(BioSimpleImageFieldScript, this.GetType().Assembly.FullName);
            baseReferences.Add(newRef);
            return baseReferences;
        
 
        /// <summary>
        /// Gets the script descriptors.
        /// </summary>
        /// <returns></returns>
        public override IEnumerable<ScriptDescriptor> GetScriptDescriptors()
        
            var lastDescriptor = (ScriptControlDescriptor)base.GetScriptDescriptors().Last();
 
            if (this.DisplayMode == FieldDisplayMode.Write)
            
                lastDescriptor.AddElementProperty("selectLink", this.SelectLink.ClientID);
                lastDescriptor.AddComponentProperty("windowManager", this.RadWindowManager.ClientID);
            
            if (this.DisplayMode == FieldDisplayMode.Read)
            
                lastDescriptor.AddElementProperty("imageControl", this.ImageControl.ClientID);
            
 
            yield return lastDescriptor;
        
 
        #endregion
 
        #region Private Fields
 
        private const string BioSimpleImageFieldScript = "SitefinityWebApp.Content.field_controls.BioSimpleImageField.BioSimpleImageField.js";
 
        #endregion
    

Really hoping to get to upgrade to 4.1, but it's looking like we'll stay on 4.0 due to what we've experienced today.

Anyone able to help out on this?

Thanks

- William

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

Sorry, I solved that fairly easily. 

Just had to rename controls on the page, three of them all told.  Works fine now.

Thanks.

Posted by Community Admin on 12-May-2011 00:00

Dear William,

I have exactly the same problem when trying to add a custom news item field for the Image Selector.

I get the same exception.

I cannot, however, follow your solution to the problem. Which controls do I have to rename exactly?

Thanks in advance.

Ruben

Posted by Community Admin on 18-May-2011 00:00

Same problem here. I don't understand what you did to resolve this issue. Could you please follow up on this?


Kind regards,

Rob Houweling

Posted by Community Admin on 18-May-2011 00:00

Hi William,

In your template I don;t see that you have a reference to the required control

textBox_write


Here is also the conditional template

<%@ Control Language="C#" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %>
 
<sf:ConditionalTemplateContainer ID="conditionalTemplate" runat="server">
    <Templates>
        <sf:ConditionalTemplate Left="DisplayMode" Operator="Equal" Right="Read" runat="server">       
            <sf:SitefinityLabel id="titleLabel_read" runat="server" WrapperTagName="div" HideIfNoText="false" CssClass="sfTxtLbl"></sf:SitefinityLabel>
            <sf:SitefinityLabel id="textLabel_read" runat="server" WrapperTagName="div" HideIfNoText="false" CssClass="sfTxtContent"></sf:SitefinityLabel>
            <sf:SitefinityLabel id="descriptionLabel_read" runat="server" WrapperTagName="p" HideIfNoText="false" CssClass="sfDescription"></sf:SitefinityLabel>
        </sf:ConditionalTemplate>
        <sf:ConditionalTemplate Left="DisplayMode" Operator="Equal" Right="Write" runat="server">
            <asp:Label ID="titleLabel_write" runat="server" CssClass="sfTxtLbl" />
            <asp:LinkButton ID="expandButton_write" runat="server" OnClientClick="return false;" CssClass="sfOptionalExpander" />
            <asp:Panel ID="expandableTarget_write" runat="server" CssClass="sfFieldWrp">
                <asp:TextBox ID="textBox_write" runat="server" CssClass="sfTxt" />
                <sf:SitefinityLabel id="descriptionLabel_write" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfDescription" />
                <sf:SitefinityLabel id="exampleLabel_write" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfExample" />
            </asp:Panel>
        </sf:ConditionalTemplate>
    </Templates>
</sf:ConditionalTemplateContainer>

This control is set as required inside TextField class when we make a control reference. If the control does not exist into the template or it could not by found by this.Container (/Represents base implementation for template container.Template containers are controls that are used as containers for other controls defined through control templates (ITemplate))/we thrown an error.

Regards,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 18-May-2011 00:00

Hi Ivan,

Your solution makes sense. However, I tried one of the samples provided on the blog of Slavo Ingilizov to create a thumbnail selector for the news content type (http://www.sitefinity.com/blogs/slavoingilizov/posts/11-02-11/creating_a_thumbnail_selector_for_news_items.aspx)
The provided sample code is incorrect. I fixed the textbox id, after that it complains about the expandButton_write control and after that on the "expandableTarget_write". "_write" is missing from all three of the id's of the controls.
This is why the errors appear.

So the solution for anyone using Slavo's sample is to rename the following items in the SimpleImageField.ascx:
textBox => textBox_write
expandButton => expandButton_write
expandableTarget => expandableTarget_write

Hope this helps.


Rob

Posted by Community Admin on 18-May-2011 00:00

Hi William,

The provided code was written before the SP1, so there might be some changes. When the code was published it was working fine. Slavo will take a look at this post of his personal blog and see if there are issues. Thanks for your input here.

Greetings,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 18-May-2011 00:00

Ivan,

I hate to say it, but imho this is a serious breaking change. I could not find it on the breaking changes list of SP1 (http://www.sitefinity.com/versionnotes.aspx?id=2459).


Rob

Posted by Community Admin on 18-May-2011 00:00

Sorry not to get back to this sooner.

Rob's three controls were the three controls I was talking about.  My custom controls also work in SP1. 

- William

This thread is closed