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

Forums / Developing with Sitefinity / Custom Control - Error - The control must be assignable from type

Custom Control - Error - The control must be assignable from type

3 posts, 1 answered
  1. Kameron
    Kameron avatar
    9 posts
    Registered:
    07 Nov 2011
    22 Feb 2012
    Link to this post
    Hello. I am trying to implement a custom control and am getting this error:
    A required control was not found in the template for "YRMC.Sitefinity.Resources.Views.Census.ascx". The control must be assignable from type "System.Web.UI.WebControls.Label" and must have ID "WCnt".

    Here is the ASCX:
    <asp:Table ID="MyCensus" runat="server">
        <asp:TableRow>
            <asp:TableCell ColumnSpan="2">West Campus</asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell>Census</asp:TableCell>
            <asp:TableCell>% Capacity</asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell BackColor="Silver"><asp:Label ID="WCnt" runat="server" Text=" " /></asp:TableCell>
            <asp:TableCell ID="TCWPcn" runat="server"><asp:Label ID="WPcn" runat="server" Text=" " /></asp:TableCell>
        </asp:TableRow>
         
        <asp:TableRow>
            <asp:TableCell ColumnSpan="2">East Campus</asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell>Census</asp:TableCell>
            <asp:TableCell>% Capacity</asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell BackColor="Silver"><asp:Label ID="ECnt" runat="server" Text=" " /></asp:TableCell>
            <asp:TableCell ID="TCEPcn" runat="server"><asp:Label ID="EPcn" runat="server" Text=" " /></asp:TableCell>
        </asp:TableRow>
    </asp:Table>
    As you can see there is a label called WCnt. Here is .cs code that the error is having an issue:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.Odbc;
    using System.Drawing;
    using System.Web.UI.WebControls;
    using Telerik.Sitefinity;
    using Telerik.Sitefinity.Modules.Pages.Web.UI;
    using Telerik.Sitefinity.Web;
    using Telerik.Sitefinity.Web.UI;
    using Telerik.Web.UI;
     
     
    namespace YRMC.Sitefinity.Web.UI
    {
        [RequireScriptManager]
        public class Census : SimpleView
        {
            private Int32 PatientCount = 0;
            private Double PatientPercentage = 0.0;
     
            protected override string LayoutTemplateName
            {
                get { return "YRMC.Sitefinity.Resources.Views.Census.ascx"; }
            }
     
            protected virtual Table MyCensus
            {
                get { return this.Container.GetControl<Table>("MyCensus", true); }
            }
     
            protected virtual Label WCnt
            {
                get { return this.Container.GetControl<Label>("WCnt", true); }
            }
    I am puzzled on this. Kameron
  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    22 Feb 2012
    Link to this post
    This might not be correct as I've never built my tables that way, but could it be that the Wcnt label is not accessible at design time because it's added to the MyCencus server control?

    Similar to how you can't access items inside a repeater template directly, but instead have to do some kind of "FindControl"...

    Have you tried doing something like MyCensus.Controls.FindControl("Wcnt")?

    Again, this is just off the top of my head, so I might be wrong about how that works...
    Answered
  3. Kameron
    Kameron avatar
    9 posts
    Registered:
    07 Nov 2011
    23 Feb 2012
    Link to this post
    Thank you for this. I changed my code to do a find instead and also changed the table from being a .net table to a html table and now it is working.

    Thanks again.
3 posts, 1 answered