为什么 ContentPlaceHolder 内部的代码不会引发异常?
据我所知,当子级与主级合并时,放置在 ContentPlaceHolder
中的任何内容都会被简单地覆盖。这可以进行一些有趣的故障排除。我遇到过一种情况,我所有的 JavaScript 根本无法工作。一段时间后,我注意到有人将 .Master 的所有标头信息放入标头的 ContentPlaceHolder
中。
所以这让我想知道......为什么在占位符内找到内容时 ASP.NET 不抛出异常?有什么方法可以合法地将内容放在这里吗?你为什么要这么做?或者,这是技术限制吗?
AFAIK anything placed inside ContentPlaceHolder
is simply overwritten when the child merges with the Master. This can make for some interesting troubleshooting. I had a situation where all my javascript would simply not work. After a while I noticed somebody had placed all the header information for the .Master inside the ContentPlaceHolder
for the header.
So this leaves me to wonder...Why doesn't ASP.NET toss an exception when content is found inside the placeholder? Is there some way to place content inside here legally? Why would you ever want to do that? Or, is this a technical limitation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信,如果没有子项覆盖内容占位符,这是提供默认模板的一种方法。如果子页面未实现该内容部分,则默认值将出现在其位置。
HTH。
I believe this is a way to supply a default template if no child overrides the content placeholder. If the child page doesn't implement that content section, then the default appears in its place.
HTH.