Neither render any markup of their own (which can be a very good thing). However, a Placeholder
may contain child controls, whereas a Literal
cannot.
By comparison, a Placeholder
can contain other controls, but does not have a Text
property.
I'm wondering which control/approach should we use for just adding generated markup and nothing more.
If by "generated" you mean the end result is a string, I would use a Literal
. If you are generating a control tree, then append those controls to a Placeholder
.
Or, if you want to omit the declaration of a server control completely:
<h2>Hello World</h2>
<p>The following is generated markup.</p>
<%= base.GetGeneratedMarkup() %>
I believe a Literal
is still generated under the hood for this, but it allows you to mix generated content with the markup portion of your page/control (similar to Razor).