locked
Displaying HTML data in a field RRS feed

  • Question

  • User-474154156 posted
    Hi all, You'll have to excuse my lack of knowledge, I'm pretty new to Dynamic data sites. I have some HTML stored in a field in my database. When it gets displayed in either a list or details view, the HTML gets encoded. I don't want this to happen, I need it to be rendered as HTML. I have taken a look in the standard text field template and changed the mode of the literal control to "passthrough" but the data still gets HtmlEncoded. What am I missing? Thanks in advance. Chris.
    Wednesday, September 10, 2008 5:53 AM

Answers

  • User-797310475 posted

    Hi Chris, sorry for the confusion. Try binding the Label to the FieldValue property, instead of the FieldValueString property (which gets html encoded; we are looking at ways of overriding this behavior in the next version).

    To others responding on this thread: please look at the forum a question was posted to as it usually provides the context for the answer that a user is looking for. In this case the question refered to the Dynamic Data feature which is new in ASP.NET 3.5 SP1.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 10, 2008 2:18 PM

All replies

  • User-850316366 posted

    I didn't get the meaning of encoded. But still you can use the simplest way of assigning the html text from database to a Textbox.text. It will be rendered properly as an HTML.

    Wednesday, September 10, 2008 7:20 AM
  • User-319574463 posted

     Can you insert the HTML into a table cell using the InnerHtml property?

    Wednesday, September 10, 2008 7:36 AM
  • User-474154156 posted

    This won't make any sense unless you know a bit about dynamic data sites.

    In a dynamic data site, the framework loads up the FieldTemplates control for whatever type of data you're trying to display. In this case (this field is a string (varchar)) it's the Text.ascx FieldTemplate that gets used. Inside Text.ascx there is simply a literal control to display the data. The problem that I'm having is that the data is being HTMLEncodedby the Dynamic Data Framework before it goes into the literal control. So for example <br /> is actually displayed on the screen rather than a line break. I'd like to stop this happening as I want my line breaks.

     Thanks.

    Wednesday, September 10, 2008 9:03 AM
  • User-797310475 posted

    Hi Chris, sorry for the confusion. Try binding the Label to the FieldValue property, instead of the FieldValueString property (which gets html encoded; we are looking at ways of overriding this behavior in the next version).

    To others responding on this thread: please look at the forum a question was posted to as it usually provides the context for the answer that a user is looking for. In this case the question refered to the Dynamic Data feature which is new in ASP.NET 3.5 SP1.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 10, 2008 2:18 PM
  • User-474154156 posted

    Excellent that did the trick, many thanks.

    This is probably one of the ideas you've already thought of but just to let you know the first thing I looked for was in the DisplayFormat attribute

    [DisplayFormat(HtmlEncode=false)]

    Chris.

    Thursday, September 11, 2008 5:54 AM