views:

117

answers:

2

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?

+4  A: 

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.

meep
+1  A: 

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.

Amarghosh