Sometimes you have to bend a little, and in this case to
document things I'd
add a comment to the code so that the reason it's squashed
is noted in how
the UI renders it.
The main thing is that sometimes the actual line breaks in
the source code
do affect the UI layout, that's the real deal.
-tom m
-----Original Message-----
From: Owen Blacker [mailto:owen flirble.org] On Behalf Of
Owen Blacker
Sent: Friday, July 21, 2006 1:37 AM
To: aspnet-controlbuilding aspadvice.com
Cc: aspnetv2-customcontrols aspadvice.com
Subject: [aspnet-controlbuilding] Re: UNANSWERED: Templates
controls: cannot
have children of type 'LiteralControl' (fwd)
Tom,
Yes, that's exactly what my problem is -- the pretty
layout.
But I don't want to have to force developers not to use
pretty layout.
It leads to code that's difficult to read and hard to
maintain. There must
be an actual solution to this, surely?
Owen
tom m wrote (2006-07-20 T 14:13 -0700):
> From: tom m <timallard msn.com>
> Reply-To: aspnet-controlbuilding aspadvice.com
> Return-Path:
<bounce-aspnet-controlbuilding-94611 aspadvice.com>
> To: aspnet-controlbuilding aspadvice.com
> Envelope-To: owen plum.flirble.org
> Message-ID:
<BAY110-DAV9076403376437177385DCA3610 phx.gbl>
> X-Originating-Ip: [68.228.212.50]
> X-Mailer: Microsoft Office Outlook 11
> X-Spam-Status: No, score=-2.6 required=10.0
tests=BAYES_00 autolearn=ham
> version=3.1.1
> Date: Thu, 20 Jul 2006 14:13:44 -0700
> Delivery-date: Thu, 20 Jul 2006 22:46:34 +0100
> Subject: [aspnet-controlbuilding] RE: UNANSWERED:
Templates controls:
cannot
> have children of type 'LiteralControl' (fwd)
>
> 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.archibald sa-consult.com]
> Sent: Thursday, July 20, 2006 10:15 AM
> To: aspnet-controlbuilding aspadvice.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:owen flirble.org] On Behalf Of
Owen Blacker
> Sent: Thursday, July 20, 2006 7:29 AM
> To: aspnet-controlbuilding aspadvice.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:owen flirble.org] On Behalf Of Owen Blacker
>> Sent: Thursday, July 20, 2006 4:27 AM
>> To: aspnet-controlbuilding aspadvice.com
>> Subject: UNANSWERED: [aspnet-controlbuilding]
Templates controls:
>> cannot have children of type 'LiteralControl'
(fwd)
>>
>> ---------- Forwarded message ----------
>> From: Owen Blacker <owen blacker.me.uk>
>> To: aspnet-controlbuilding aspadvice.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
a> and http://masl.to/?P40821B6D
a>, 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
>
--
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
|