0
工作,在關於解決方案: ASP.Net: User control with content area, it's clearly possible but I need some details與內容模板ASP.net自定義控件並沒有爲我
我試圖做同樣的,這裏是我的代碼:
控制代碼背後:
[ParseChildren(true, "Content")]
[PersistChildren(false)]
public partial class SlidingPanelControl : System.Web.UI.UserControl
{
protected override void OnInit(EventArgs e)
{
phContent.Controls.Add((Control)_content);
base.OnInit(e);
}
protected void Page_Load(object sender, EventArgs e)
{
}
private PlaceHolder _content;
[PersistenceMode(PersistenceMode.InnerProperty)]
public PlaceHolder Content { get { return _content; } set { _content = value; } }
}
而且控制ASPX:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SlidingPanelControl.ascx.cs" Inherits="Photography.Controls.MbExtruder.SlidingPanelControl" %>
<div>
<asp:Panel ID="pnlLockable" runat="server" Visible="False">
<asp:PlaceHolder runat="server" ID="phContent" />
</asp:Panel>
</div>
這是我如何用我的主要頁面的控制:
<uc1:SlidingPanelControl runat="server" ID="SlidingPanelControl"
Title="About" Position="right" Opacity="1" WidthInPixels="600">
<Content><h1>hello world</h1></Content>
</uc1:SlidingPanelControl>
這並沒有爲我工作,也沒有呈現HTML到控制佔位符。雖然當我調試控件的OnInit時,我可以看到_content控件包含我設置的所有html(即本例中的<h1>Hello World</h1>
)
任何猜測我在做什麼錯?
感謝
嘗試兩個:(仍然相同的結果 – Bishoy
@Bishoy編輯我的答案與新的解決方案 – Lesmian