在 C# 中获取 ContentPlaceHolder 的内容

发布于 2024-09-07 18:46:27 字数 188 浏览 1 评论 0原文

我有一个包含多个 ContentPlaceHolders 的母版页。其中之一有时会是空的。如果它们都有内容,我想使缓冲区可见,以便它们之间有一些空间,但否则应该保持隐藏。

我的问题是,如何从母版页的 C# 代码隐藏中确定子页面的 ContentPlaceHolder 是否分配有任何内容?我真正想要的是一个布尔是/否答案。

谢谢!

I've got a Master Page with multiple ContentPlaceHolders. One of them will sometimes be empty. If they both have content, I'd like to make visible a buffer so there is some space between them, but this should remain hidden otherwise.

My question is, how can I determine from the C# code-behind of my Master Page whether the ContentPlaceHolder of a child page has any content assigned to it? All I really want is a boolean yes/no answer.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ゞ花落谁相伴 2024-09-14 18:46:27

也许

YourContentPlaceHolder.Controls.Count > 0

这对你有用吗?

perhaps

YourContentPlaceHolder.Controls.Count > 0

Would that work for you?

死开点丶别碍眼 2024-09-14 18:46:27

也许我错过了一些东西,但看来你只需要留出空间。为什么不直接用 padding-bottom 将第一个 ContentPlaceHolder 包装在 div 中?可能有更有效的方法来做到这一点,但你明白了。

Maybe I am missing something, but it seems you just need to get spacing. Why not just wrap the first ContentPlaceHolder in a div with a padding-bottom? There may be a more efficient way to do this, but you get the idea.

娇纵 2024-09-14 18:46:27

您可以以编程方式将 div 添加到您的第一个 ContentPlaceHolder 中,其中包含...

<div class="spacer" />

并且在您的 css 中有这样的...

div.spacer { margin-bottom: 5ex; }

您可能需要在 div 中放置一个   来解决一些浏览器错误:)

You could programmatically add a div to your first ContentPlaceHolder with something like ...

<div class="spacer" />

and in your css have this ...

div.spacer { margin-bottom: 5ex; }

you may need to put a   in the div to get around some browser bugs :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文