List Info

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




UNANSWERED: Templates controls: cannot have children of type 'LiteralControl'
user name
2006-07-20 21:13:44
I've noticed that line breaks in the source code matter to
the parser in
net v2. 

So, check that these "whitespaces" aren't
simply line breaks from the pretty
layout getting parsed as a space, especially if you use auto
formatting. 

Removing them may remove the space ... it has for me at
times within
controls' item/edit templates so may work here.

ymmv,

tom mallard
   .net web applications
      consumer industrial design 

-----Original Message-----
From: Steven Archibald [mailto:steven.archibaldsa-consult.com] 
Sent: Thursday, July 20, 2006 10:15 AM
To: aspnet-controlbuildingaspadvice.com
Subject: [aspnet-controlbuilding] RE: UNANSWERED: Templates
controls: cannot
have children of type 'LiteralControl' (fwd)

Hmm. Then can you replace the white space w/   ? 
Ugly, but it might work.


-----Original Message-----
From: Owen Blacker [mailto:owenflirble.org] On Behalf Of
Owen Blacker
Sent: Thursday, July 20, 2006 7:29 AM
To: aspnet-controlbuildingaspadvice.com
Subject: RE: UNANSWERED: [aspnet-controlbuilding] Templates
controls: cannot
have children of type 'LiteralControl' (fwd)

No, it's definitely the whitespace.  If I remove the
whitespace, it works
quite happily.  As it is, I've instructed
AddParsedSubObject to ignore
everything that isn't a TableCell (or descendent) and it's
working, but I'd
rather write something that's less of a hack.

Sorry, I prolly wasn't very clear.  HeaderTemplate and
ItemTemplate both
render into TableRow controls, the RepeatingInputRow control
creating a
Table.  The table construction isn't the issue, it's
definitely the
whitespace LiteralControl instances in the code-forward. 
Most odd.

Thanks for your suggestion, though.


Owen

Steven Archibald wrote (2006-07-20 T 06:45 -0700):
> 
> I doubt it is the whitespace it is complaining about.
>
> It is unlikely that <asp:TableHeaderCell ...> is
a valid nested item 
> immediately below <HeaderTemplate ...>.  You may
assume that a table 
> is eventually being rendered, but the XML used for
validating your 
> document is unlikely to allow this construction. If,
immediately after 
> your <HeaderTemplate > tag, you nested a
<asp:Table>, then a 
> <asp:TableHeaderRow ...>, then an <asp:
...>, etc. to construct a 
> valid table, you might have better luck.
>
> -----Original Message-----
> From: Owen Blacker [mailto:owenflirble.org] On Behalf Of
Owen Blacker
> Sent: Thursday, July 20, 2006 4:27 AM
> To: aspnet-controlbuildingaspadvice.com
> Subject: UNANSWERED: [aspnet-controlbuilding] Templates
controls: 
> cannot have children of type 'LiteralControl' (fwd)
>
> ---------- 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



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 )