DaveDev
DaveDev

Reputation: 42185

What's the difference between PlaceHolder and <div />?

In an ASP.NET project I have the following HTML:

<asp:PlaceHolder ID="plcTitle" runat="server"></asp:PlaceHolder>

<div id="divStrapline" runat="server" />

which are populated with this code:

if (this.TitlePanel != null)
{
    plcTitle.Controls.Add(this.TitlePanel);
}

if (this.Strapline != null)
{
    divStrapline.Controls.Add(this.Strapline);
}

Are they both the same thing? Is either better than the other? Why?

Upvotes: 2

Views: 2786

Answers (2)

Amarghosh
Amarghosh

Reputation: 59451

Empty div tags (and other container tags like p etc) closed in the opening element itself (as in <div/> instead of <div></div>) might lead to issues in some browsers. Browsers might ignore the fact that it is closed with a / and consider it as a new div and thus break the subsequent mark up.

I once had this issue with Firefox: I was generating html with minidom xml library in python which represented empty div as <div /> - it broke the remainder of my mark up messing up with the subsequent divs. I ended up adding comment nodes to empty elements to make sure that they have a separate closing tag.

Upvotes: 1

janhartmann
janhartmann

Reputation: 15003

The <asp:PlaceHolder /> does not generate a div tag.

The PlaceHolder Web server control does not have any visible output and is used as a place holder when we add controls at run time.

Upvotes: 4

Related Questions