Bogdan Stăncescu
Bogdan Stăncescu

Reputation: 5450

ContentPlaceholder in aspx files

I need the equivalent of a ContentPlaceholder in an ASPX file (as opposed to a Master page). I don't want to use a dedicated WebControl descendant (TextBox, Label, etc), because using those forces me to use server-side forms, and I don't like that (VS pollutes the HTML with all sorts of crap when I do that).

So, what control should I use in ASPX files if I only need to inject a simple HTML fragment that's rendered in the code behind at runtime?

Upvotes: 0

Views: 2078

Answers (2)

Bogdan Stăncescu
Bogdan Stăncescu

Reputation: 5450

Ok, I found the answer, with assistance from Mortuus who helped locate the namespace I had to look into: I'm using PlaceHolder instead of ContentPlaceHolder – that's all there is to it. ContentPlaceHolder is for Master pages, PlaceHolder is for ASPX pages, for some reason.

Upvotes: 0

migfab
migfab

Reputation: 81

If you have a page like so:

<body>
    <asp:Literal runat="server" id="htmlPlaceholder"></asp:Literal>
</body>

You can assign HTML text to the label, which will be rendered as actual HTML, with a code file similar to the one below:

protected void Page_Load(...)
{
    htmlPlaceholder.Text = @"<div>Content</div><br /><div>etc...</div>
}

Upvotes: 2

Related Questions