[英]What's the difference between PlaceHolder and <div />?
In an ASP.NET project I have the following HTML: 在ASP.NET项目中,我具有以下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?
为什么?
The <asp:PlaceHolder />
does not generate a div
tag. <asp:PlaceHolder />
不会生成div
标签。
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. 当我们在运行时添加控件时,PlaceHolder Web服务器控件没有任何可见输出,并且用作占位符。
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. 在开始元素本身中关闭的空
div
标签(以及其他容器标签,如p
等)(如<div/>
而不是<div></div>
)可能会导致某些浏览器出现问题。 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. 浏览器可能会忽略使用
/
关闭的事实,并将其视为新的div,从而破坏了后续标记。
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. 我曾经在Firefox中遇到过这个问题:我在python中使用minidom xml库生成了HTML,该库将空div表示为
<div />
-它破坏了我标记的其余部分,使后续的div混乱。 I ended up adding comment nodes to empty elements to make sure that they have a separate closing tag. 最后,我向空元素添加了注释节点,以确保它们具有单独的结束标记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.