I have a simple ASPX
page that inherits from MasterPage
:
(Popup.master)
<div class="text_container">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
(Privacy.aspx) Privacy
<asp:Content ID="BodyContent" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
I need to add a HTML content inside the Privacy.aspx.cs:
public partial class Privacy : System.Web.UI.Page
{
protected override void OnPreInit(EventArgs e)
{
ContentPlaceHolder body = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
I saw this example but as I see I need asp control inside.
How to add just HTML content to ContentPlaceHolder1
?
A ContentPlaceHolder is intended to give you the ability to add controls in your page markup with a Content control and have them appear within the context of your master page. Given that, in Privacy.aspx you can add a generic html control in BodyContent
Content Control and set the InnerContent property on the added control within your code behind.
Markup
<asp:Content ID="BodyContent" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<span id="SpanContent" runat="server"></span>
</asp:Content>
Code Behind
protected void Page_Load(object sender, EventArgs e)
{
SpanContent.InnerHtml = "<b>Hello!</b>";
}