Hi, I have made a little custom control which has collection of inner properties. I've also successfully tested a custom control which accepted "literal content" (innertext) into a default property. I have both models working separately, but I'd like to combine the two into one control. That is, I want to define my control on the page like this:

<mystuff:sitemenu runat="server">
  <menuitem name="something" url="something.aspx" />
  <menuitem ... />
  some literal content here which ends up in a default property string

My code for the control, which is working with the inner properties (but not the literal content) is as follows:

Namespace mystuff

  <ParseChildren(True, "menuitem")> _
    <PersistChildren(False)> _
    Partial Public Class sitemenu
      Inherits System.Web.UI.UserControl

      Private _menuitems As New Hashtable

    <PersistenceMode(PersistenceMode.InnerProperty)> _
    Public Property menuitem() As clsMenuItem
      (get and set stuff - adds instances of clsMenuItem to _menuitems hashtable)
    End Property

    Public Class clsMenuItem
      (defines properties which are the attributes for each menuitem)
    End Class   

End Namespace

The above is working for inner properties of the control. I have added some code to the above (see below), which the *IDE* accepts as allowing the literal content (no wiggly error lines appear yay!) but when I run the page, the HTML parser throws the error "Literal content is not allowed within (my user control)"

This is what I added (as well as changing the default property of the class to "myliteralcontent"):

<PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty)> _
    Public Property myliteralcontent() As String
      (gets and sets)
    End Property

That resulted in the IDE playing nice and recognising the literal content as well as the inner properties! But the runtime parser is the problem. What do I need to add to my code to get the parser to accept the literal content?

Many thanks if anyone can help!

Found the answer, quite by accident. Although it seems we're not allowed to mix inner properties and literal text on the same level, I was able to place some literal text (even HTML) inside an inner property tag. For example:

Instead of this:

<mystuff:sitemenu runat="server">
  <menuitem name="something" url="something.aspx" />
  <menuitem ... />
  some literal content here

It seems acceptable to do this:

<mystuff:sitemenu runat="server">
  <menuitem name="something" url="something.aspx" />
  <menuitem ... />
    <p>some content here, even html tags</p>

Works perfectly fine that way!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.