Output encoding issue

Hello all!

I’m trying to use a BulletedList to output some links. When the list renders, all the link tags are encoded, so they are displayed to the user instead of being rendered as links.

Is there a way to make the BulletedList not do this? I’m doing a foreach over a custom object collection where each object has a string representing a link as a property. I just want to build a list of links and I thought a BulletedList was a good way to do it. Is there a better way or a way that doesn’t encode the output?

Thanks!

If this is MVC use MvcHtmlString.Create(value).
If it’s webforms use Server.HtmlDecode(value) - I think…

This is webforms. Where would I use that? When I create and add the ListItem during the dropdown’s change event? That doesn’t seem right. I would think that the encoding is happening during the rendering of the page.

I could have swore there was an attribute you can set to the tell the server to not encode the output…

Add it to the code-behind:


String DecodedString = @"<a href="wordlife.html">Song</a>";
Output.Text= Server.HtmlDecode(DecodedString);

It outputs an HTML Link. Very simple example, but it is a start…

Thanks for the suggestions, but Server.HtmlDecode doesn’t work for a BulletedList. I believe that the encoding isn’t happening during the creation of the list item, but when the control is being rendered.

The “thing” I was thinking of was a page directive that disabled input validation, but I didn’t find a way to get that to work within a user control.

I’m going to switch to a repeater and see if I have better luck.

Thanks anyway!