Reputation: 24160
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?
Upvotes: 2
Views: 2966
Reputation: 21
This has worked for me:
<%# Server.HtmlDecode(DataBinder.Eval(Container.DataItem, "ItemName")) %>
Upvotes: 2
Reputation: 4766
What about literal with mode="encode"
<asp:Literal ID="Literal1" runat="server" Mode="Encode" />
Upvotes: 4
Reputation: 9709
You can use the literal control which has a mode property with enumeration Encode,PassThrough,Transform.
Upvotes: 2
Reputation: 17680
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>
Upvotes: -1