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

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 filled 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? Is it better than the other? Why?
+2


a source to share


2 answers


<asp:PlaceHolder />

does not generate a tag div

.



The PlaceHolder web server control has no visible results and is used as the place owner when we add the controls at runtime.

+4


a source


Empty tags div

(and other container tags such as p

, etc.) closed in the opening element itself (as in <div/>

instead <div></div>

) can lead to problems in some browsers. Browsers can ignore the fact that it is closed with /

and treats it as a new div and thus breaks the subsequent mark.



I once had this problem with Firefox: I was generating html with a mini xml library in python that represented an empty div as <div />

- it broke the rest of my label, confusing it with subsequent divs. I ended up adding comment nodes to empty elements to make sure they have a separate end tag.

+1


a source







All Articles