0

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?

1 Answer 1

1

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>";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.