Custom Control - Error - The control must be assignable from type
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"
.
<
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
>
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
);
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...
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.