建議的解決方案對我無效。我發現了以下解決方案: 要麼讓您的用戶控件繼承Panel
而不是UserControl
,或者如果您擁有多於一個的內容,請使您的內容字段爲PlaceHolder
s而不是簡單的Control
s。
添加了[PersistenceMode(PersistenceMode.InnerProperty)]
以避免XHTML驗證警告。
public partial class DrawerControl : UserControl
{
[PersistenceMode(PersistenceMode.InnerProperty)]
public PlaceHolder BodyContent { get; set; }
[PersistenceMode(PersistenceMode.InnerProperty)]
public PlaceHolder GripContent { get; set; }
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
phBodyContent.Controls.Add(BodyContent);
phGripContent.Controls.Add(GripContent);
}
}
phBodyContent
和phGripContent
是PlaceHolder
秒。
這樣我可以用我的控制裝置與ASPX任何內容:
<local:Drawer ID="ctlDrawer" runat="server">
<BodyContent>
<!--Insert any ASP content here-->
</BodyContent>
<GripContent>
<!--Insert any ASP content here-->
</GripContent>
</local:Drawer>
哇...工作就像一個魅力... 但...可以üPLZ告訴我如何得到該內部的HTML,因爲我沒有得到這種屬性..像** this.InnerHtml或this.Children ** .. ??? – Manish 2009-08-24 06:23:29
您可以使用[ParseChildren(true,「Body」)]和一個名爲字體類型爲「Body」的屬性。這會將InnerHtml的內容放入ParseChildren註釋中作爲第二個參數命名的任何屬性。 – 2010-10-20 22:43:41