locked
Mixing inner properties and some "literal content" RRS feed

  • Question

  • User-859254234 posted

    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.  That is, I want to define my control on the page like this:

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

      ...

      some literal content here which ends up in a default property string

    </mystuff:sitemenu>


    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!


    Thursday, September 17, 2009 9:43 AM

Answers

  • User-2106054853 posted

     Hi,

    This can be done by using custom ControlBuilder:

     Public Class MyControlBuilder
      Inherits ControlBuilder


     End Class

     Public Class MySubControl
      Inherits Label

     End Class

     <ControlBuilder(GetType(MyControlBuilder))> _
     Public Class MyControl
      Inherits Panel
      Private Property SubControl() As MySubControl
       Get
       Set(ByVal value As MySubControl)
       End Set
       End Get
      protected override void AddParsedSubObject(Object obj)

       MyBase.AddParsedSubObject(obj)
      End Property

     

     

    <cc1:MyControl ID="MyControl1" runat="server">

     

    <cc1:MySubControl Text="abc" ID="MySubControl1" runat="server"></cc1:MySubControl>

    Hello World

     

    </cc1:MyControl>

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 20, 2009 10:58 PM

All replies

  • User-2106054853 posted

     Hi,

    This can be done by using custom ControlBuilder:

     Public Class MyControlBuilder
      Inherits ControlBuilder


     End Class

     Public Class MySubControl
      Inherits Label

     End Class

     <ControlBuilder(GetType(MyControlBuilder))> _
     Public Class MyControl
      Inherits Panel
      Private Property SubControl() As MySubControl
       Get
       Set(ByVal value As MySubControl)
       End Set
       End Get
      protected override void AddParsedSubObject(Object obj)

       MyBase.AddParsedSubObject(obj)
      End Property

     

     

    <cc1:MyControl ID="MyControl1" runat="server">

     

    <cc1:MySubControl Text="abc" ID="MySubControl1" runat="server"></cc1:MySubControl>

    Hello World

     

    </cc1:MyControl>

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 20, 2009 10:58 PM
  • User-859254234 posted

    Thanks Allen, I'll give that a try!

    Saturday, September 26, 2009 1:02 AM