Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error: Content is not allowed between the opening and closing tags for element

662 views
Skip to first unread message

Allan Ebdrup

unread,
Jan 30, 2006, 2:55:28 AM1/30/06
to
I have a ascx webcontrol that I register with:
<%@ Register Src="../Controls/Default/Library/Basket/Basket.ascx"
TagName="Basket"
TagPrefix="uc1" %>

and instantiate on the page with:
<uc1:Basket ID="Basket1" runat="server" />

This works without problems, Now I've added the attribute:
[ParseChildren(ChildrenAsProperties = true)]
to the basket control and added a property called Header of the type
ITemplate.
When I change my basket tag to look like:
<uc1:Basket ID="Basket1" runat="server">
<Header>Myheader</Header>
</uc1:Basket>

I get the following error on the Basket tag:
Error 1 Cannot switch views: Content is not allowed between the opening and
closing tags for element 'Basket'.

And the following error on the Header tag:
Error 2 Validation (XHTML 1.0 Transitional): Element 'header' is not
supported.


When I run the page it works fine.

What am I missing to allow tags inside the Basket controls XML?

I'm guessing it hase something to do with the designtime rendering of the
component, and that I have to implement a special designtime rendering
myself.

Kind Regards,
Allan Ebdrup


Steven Cheng[MSFT]

unread,
Jan 30, 2006, 5:45:48 AM1/30/06
to
Hi Allan,

Welcome to the MSDN newsgroup.
Regarding on the error you mentioned, it is because ASP.NET user
control(ascx control) dosn't support inner html or xml between its aspx
template tags(begin and end). Only custom web server control can support
such inner property or control template.... Also, it has no effect to
apply such attributes as "ParseChildren" to usercontrol since those
attributes is used for web server controls. You can refer to some document
in MSDN on ASP.NET UserControl and web server controls:

#Composite Control vs. User Control
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcompositecontrolvs
usercontrol.asp?frame=true

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "Allan Ebdrup" <ebd...@noemail.noemail>
| Subject: Error: Content is not allowed between the opening and closing
tags for element
| Date: Mon, 30 Jan 2006 08:55:28 +0100
| Lines: 38
| Organization: OFiR
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID: <#RatKKXJ...@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: 193.0.243.15
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:32903
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols

Allan Ebdrup

unread,
Feb 1, 2006, 6:43:01 AM2/1/06
to
Thanks for the reply Steven
Now I've created a class library with controls much like the "Developing a
Templated Databound Control" example on this page:
http://samples.gotdotnet.com/quickstart/aspplus/default.aspx?url=%2fquickstart%2faspplus%2fdoc%2fwebctrlauthoring.aspx

When I insert my control on the aspx page I still get the error "Error:
Content is not allowed between the opening and closing tags for element" and
I can't switch to design view.

How do I allow content between the opening and closing tags of the element?

Kind Regards,
Allan Ebdrup


Steven Cheng[MSFT]

unread,
Feb 2, 2006, 2:21:22 AM2/2/06
to
Thanks for your followup Allan,

For custom web server control which inner content, it also differs
according to what the inner content will represent. Generally, asp.net
webserver control can let use map its control properties to be persisted as
inner properties of the control tag. This can be done just through some
attributes. Here are some examples which persisted some properties as inner
element in server control's tag:

#Custom ASP.NET Server Control for Displaying RSS Feeds
http://aspnet.4guysfromrolla.com/articles/102903-1.aspx

#ASP.NET Color DropDown Control
http://www.codeproject.com/aspnet/HtmlColorDropDown.asp

Also, if you want to put discretionary content within server control's tag,
we may need to provide our custom control builder to parse the content
also. You can get some idea from the following web article:

#ASP.NET Query control
http://www.codeproject.com/aspnet/MikEllASPNetQuery.asp

Allan Ebdrup

unread,
Feb 3, 2006, 6:31:36 AM2/3/06
to
Thanks for the answer Steven

Now I've addet the attributes:
[
PersistenceMode(PersistenceMode.InnerDefaultProperty),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
]
to the properties in question and it works.

My next problem is that I want the Design Mode of VS.Net 2005 to show a more
meaningfull preview of what is rendered at runtime, how do I add code to
display a preview in design mode?
Like the repeater control does.

Kind Regards,
Allan Ebdrup


Steven Cheng[MSFT]

unread,
Feb 6, 2006, 4:08:14 AM2/6/06
to
Thanks for your response Allan,

Glad that you've made further progress on this. As for generating render
html for design-time in VS IDE, we can consider define a custom control
designer class(derived from ControlDesigner class) for our custom class. We
can apply Designer to a control through the "DesignerAttribute". Also, the
ControlDesigner.GetDesignTimeHtml method(virtual method) is the one which
used to return the design-time html content that will be displayed in VS
ide. We can override this method to write our own design-time presentation
logic in our custom control designer 's code. Here are some useful
reference and article on creating custom control designer:

#ASP.NET Custom control with designer integration
http://www.theserverside.net/discussions/thread.tss?thread_id=25105

#ASP.NET Control Designers Overview
http://msdn2.microsoft.com/en-us/library/wxh45wzs.aspx

#ControlDesigner.GetDesignTimeHtml Method
http://msdn2.microsoft.com/en-us/library/system.web.ui.design.controldesigne
r.getdesigntimehtml.aspx

Hope this helps.

0 new messages