List Info

Thread: UNANSWERED: Templates controls: cannot have children of type 'LiteralContr




UNANSWERED: Templates controls: cannot have children of type 'LiteralContr
user name
2006-07-20 11:27:17
---------- Forwarded message ----------
From: Owen Blacker <owenblacker.me.uk>
To: aspnet-controlbuildingaspadvice.com
Date: Mon, 17 Jul 2006 18:07:19 +0100 (BST)
Delivery-date: Mon, 17 Jul 2006 19:23:11 +0100
Subject: [aspnet-controlbuilding] Templates controls: cannot
have children of
     type 'LiteralControl'

I have a templated control, that I've built with a great
deal of help
from the two articles by 4GuysFromRolla's Scott Mitchell
(http://masl.to/?S11823B6D and http://masl.to/?P40821B6D, both on
msdn.microsoft.com)

I've got it doing quite a lot of what I think I want it to,
but it's
complaining at the whitespace in the content of the
ITemplate property,
because it instantiates into a
System.Web.UI.WebControls.TableRow:

     [Browsable(false)]
     [DefaultValue(null)]
     [Description("The header template")]
     [PersistenceMode(PersistenceMode.InnerProperty)]
     [TemplateContainer(typeof(RepeatingInputRow))]
     public ITemplate HeaderTemplate {
        get { ... }
        set { ... }
     }

     protected void CreateControlHierarchy(bool
useDataBinding)
     {
        // ...
        Table container = new Table();
        TableHeaderRow thead = new TableHeaderRow();
        this.HeaderTemplate.InstantiateIn(thead);
        container.Controls.Add(thead);
        // ...
     }

The code-forward for my page includes:

     <Lego:RepeatingInputRow runat="server"
CssClass="myClass">
        <HeaderTemplate>
           <asp:TableHeaderCell
runat="server">Column
1</asp:TableHeaderCell>
           <asp:TableHeaderCell
runat="server">Column
2</asp:TableHeaderCell>
           <asp:TableHeaderCell
runat="server">Column
3</asp:TableHeaderCell>
        </HeaderTemplate>
        <ItemTemplate>
           <!-- ... -->
        </ItemTemplate>
     </Lego:RepeatingInputRow>

The whitespace between <HeaderTemplate> and
<asp:TableHeaderCell> (etc)
is causing my page to present an ArgumentException:

     'TableRow' cannot have children of type
'LiteralControl'.

   [ArgumentException: 'TableRow' cannot have children of
type 'LiteralControl'.]
    
System.Web.UI.WebControls.CellControlCollection.Add(Control
child) +181
     System.Web.UI.Control.AddParsedSubObject(Object obj)
+38
    
System.Web.UI.Control.System.Web.UI.IParserAccessor.AddParse
dSubObject(
       Object obj) +7
     ASP.owentest_aspx.__BuildControl__control3(Control
__ctrl)
       in
c:\Projects\Customisation\RedesignProtoTypeWeb\Owentest.
aspx:6
    
System.Web.UI.CompiledTemplateBuilder.InstantiateIn(Control
container) +12
    
uSwitch.Web.UI.Lego.RepeatingInputRow.PopulateTableHeader(
       TableHeaderRow container) in
      
C:\Projects\uSwitch.Web\UI.Lego\InputModule\RepeatingIn
putRow.cs:479
    
uSwitch.Web.UI.Lego.RepeatingInputRow.CreateControlHierarchy
(
       Boolean useDataBinding) in
      
C:\Projects\uSwitch.Web\UI.Lego\InputModule\RepeatingIn
putRow.cs:425
    
uSwitch.Web.UI.Lego.RepeatingInputRow.CreateChildControls()
       in
C:\Projects\uSwitch.Web\UI.Lego\InputModule\RepeatingIn
putRow.cs:581
     System.Web.UI.Control.EnsureChildControls() +97
     System.Web.UI.Control.PreRenderRecursiveInternal() +50
     System.Web.UI.Control.PreRenderRecursiveInternal() +171
     System.Web.UI.Control.PreRenderRecursiveInternal() +171
     System.Web.UI.Control.PreRenderRecursiveInternal() +171
     System.Web.UI.Control.PreRenderRecursiveInternal() +171
     System.Web.UI.Control.PreRenderRecursiveInternal() +171
     System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint,
       Boolean includeStagesAfterAsyncPoint) +5684

Does anyone know of a way I can persuade the TableRow (the
variable
thead in the C# above) to ignore the whitespace, like a
Repeater would
in its ITemplates?

Or is there something else I can do?  The only other
suggestion that
springs to mind is to use some other container and remove
all the
LiteralControls from it before adding its ControlCollection
to that of
the TableHeaderRow.

Anyone?


Owen Blacker
-- 
Owen Blacker, bond GB
Say no to ID cards: www.no2id.net
Get your mits off my bits: www.openrightsgroup.org
--
Those who would give up essential liberty to purchase a
little temporary
   safety, deserve neither liberty nor safety  -- Benjamin
Franklin, 1759


Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com


Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )