如何在 ASP.NET 中继器中对 HTML 进行编码?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
mode="encode" 的文字怎么样
What about literal with mode="encode"
您可以使用具有模式属性和枚举 Encode、PassThrough、Transform 的文字控件。
You can use the literal control which has a mode property with enumeration Encode,PassThrough,Transform.
这对我有用:
This has worked for me:
我假设您希望能够以 html 格式显示评论(带有格式等)。
将 Label 控件替换为 Literal 控件。它们都有 Text 属性,但控件将处理您的 html 内容。
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.