views:

13

answers:

1

I have a user control with a panel on it:

CustomControl.ascx

<%@ Control Language="vb" CodeBehind="CustomControl.ascx.vb" %>
<asp:Panel ID="myPanel" runat="server"></asp:Panel>

I'd lke to expose that panel as a property that I can use at design time.

CustomControl.ascx.vb

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

#Region "Members and Properties"
    <PersistenceMode(PersistenceMode.InnerProperty)> _
    Public Property SomePanel() As Panel
        Get
            Return myPanel
        End Get
        Set(ByVal value As Panel)
            myPanel= value
        End Set
    End Property

#End Region


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
         Response.Write(myPanel.HasControls.ToString())

    End Sub

End Class

And then bring the control onto a page like so:

<ucl:CustomControl runat="server">
    <SomePanel>
        <asp:Label ID="lblText" AssociatedControlID="txtBox" runat="server"></asp:Label>
        <asp:TextBox id="txtBox" runat="server"></asp:TextBox>
    </SomePanel>
</ucl:CustomControl>

When I run the page, HasControls is true but nothing is rendered. What am I doing wrong?

A: 

You could achieve a similar effect by designing your user control as a template control. It's not that hard to set up, if you choose to go the template route.

Check out this brief tutorial to determine if control templates are suitable for you:

http://msdn.microsoft.com/en-us/library/36574bf6.aspx

kbrimington