呈现空值的数据绑定控件

发布于 2024-10-20 03:34:32 字数 707 浏览 5 评论 0原文

尽管自 ASP.Net 2.0 以来我就是 Databound 控件的忠实粉丝,并且自从学习它们以来一直在使用它们,但我似乎偶然发现了这些控件似乎存在的一个未被注意到(或者更确切地说不关心)的问题。

我正在使用 ASP.Net 3.5,我注意到的问题是,当在数据控件(例如 Datalist、Gridview 等)内使用数据绑定控件(例如标签、超链接)时,即使为一列返回的值是 NULL,尽管它是一个空标签,但它仍然被渲染。

例如:我有一个Datalist,其中有一个Label,其值可能是也可能不是NULL。现在,当值不为 NULL 时没有问题,问题是当值为 NULL 时。理想情况下,不应该为没有任何值的控件呈现 HTML,但在这种情况下,将显示相应的 NULL 值控件仍在呈现。

现在,正如我之前所说,大多数人不会关心这一点,因为这不是什么大问题,但如果您考虑到该控件可能包含在父控件的层次结构中,然后重复多次的事实,这可能会显着增加 HTML 内容(因为 HTML 内容的 ID 基于父控件),而无需添加任何文本来维持文本/HTML 比例,从而成为搜索引擎回避对您的页面建立索引的原因完全。

我在其他地方找不到与此事相关的任何内容,所以我想在这里提出来。这真的是数据绑定控件的问题还是我在这里遗漏了一些东西?

帮助总是值得赞赏的。

Although I'm a huge fan of Databound controls since ASP.Net 2.0 and have been using them a lot since learning them, I seem to have stumbled upon an unnoticed(or rather not cared about) issue that these controls seem to have.

I'm using ASP.Net 3.5 and the issue that I noticed is that when using Databound controls(such as Labels, HyperLinks) inside a Data-Control(such as Datalist, Gridview etc.), even if the value returned for one column is NULL, it is still rendered albeit as an empty tag.

For eg: I have a Datalist in which I have a Label whose value may or may not be NULL. Now there's no problem when the value is not NULL, the problem is when the value is NULL. Ideally, no HTML should be rendered for a controls that don't have any value, but in this case, the HTML(<span></span> in case of the Label) of the corresponding NULL valued control is still being rendered.

Now, as I said earlier that most people won't care about this as it isn't much of an issue, but if you consider the fact that this control may be enclosed in a hierarchy of parent controls, and then repeated many a times, this could significantly increase the HTML content(since the ID of your HTML content is based on the parent controls) without any Text added to maintain the Text/HTML ratio, thereby becoming a cause for the Search Engines to shy away from indexing your pages fully.

I couldn't find anything related to this matter anywhere else so I thought to bring it up here. Is this really an issue with databound controls or am I missing something here?

Help is always appreciated.

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

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

发布评论

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

评论(1

∞梦里开花 2024-10-27 03:34:32

是的,这是有道理的,因为控件不会自动隐藏自己,即使没有内容,您也必须通过 Visible="False" 显式隐藏它们。这与数据绑定控件和非数据绑定控件是一致的。当没有内容时排除标记可能会给应用程序带来混乱,尤其是在页面使用 JavaScript 的情况下。

HTH。

Yes, that makes sense because control's don't auto hide themselves, you'd have to explicitly hide them through Visible="False", even with no content. This is consistent with the databound controls and non-databound controls alike. Excluding the markup when no content is there could potentially be chaotic to an application, especially if the page used JavaScript.

HTH.

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