2010-08-20 60 views
0

我有上面板的用戶控件:如何將Panel作爲用戶控件中的屬性公開?

CustomControl.ascx

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

我希望不要去想那些以暴露面板,我可以在設計時使用屬性。

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 

,然後將控制到一個頁面,如下所示:

<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> 

當我運行頁面,HasControls是真實的,但沒有被渲染。我究竟做錯了什麼?

回答

相關問題