如何在 ASP.NET 中继器中对 HTML 进行编码?

发布于 2024-10-08 13:42:43 字数 186 浏览 0 评论 0原文

我有一个 ASP.NET 转发器从数据库中提取评论数据。

在我的 ItemTemplate 中,我放置了一些绑定到字段(海报的用户名、日期和帖子文本)的 Label 服务器控件,但显然 Label 在显示数据之前不会通过 HtmlEncode 运行数据。

我应该使用其他控件吗?我应该如何显示来自中继器的 HTML 编码数据?

I have an ASP.NET repeater pulling comment data from a database.

In my ItemTemplate I placed some Label server controls bound to the fields (username of poster, date, and post text), but apparently Label does not run the data through HtmlEncode before displaying it.

Is there another control I should use? How should I display HTML-encoded data from a repeater?

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

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

发布评论

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

评论(4

情泪▽动烟 2024-10-15 13:42:43

mode="encode" 的文字怎么样

<asp:Literal ID="Literal1" runat="server" Mode="Encode" />

What about literal with mode="encode"

<asp:Literal ID="Literal1" runat="server" Mode="Encode" />
眼泪也成诗 2024-10-15 13:42:43

您可以使用具有模式属性和枚举 Encode、PassThrough、Transform 的文字控件。

You can use the literal control which has a mode property with enumeration Encode,PassThrough,Transform.

兔小萌 2024-10-15 13:42:43

这对我有用:

<%# Server.HtmlDecode(DataBinder.Eval(Container.DataItem, "ItemName")) %>

This has worked for me:

<%# Server.HtmlDecode(DataBinder.Eval(Container.DataItem, "ItemName")) %>
水溶 2024-10-15 13:42:43

我假设您希望能够以 html 格式显示评论(带有格式等)。

将 Label 控件替换为 Literal 控件。它们都有 Text 属性,但控件将处理您的 html 内容。

<asp:Literal>

I'm assuming you want to be able to display the comments in html (with formatting et al).

replace the Label control with an Literal control. They both have the Text property but the control will handle your html content.

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