Solved

Field that has HTML displays the code instead of the text in html

Posted on 2016-09-12
16
90 Views
Last Modified: 2016-09-12
I have an ASP page which displays 'notes'.  This notes were saved in HTML in the DB. Like :  Hello I am <strong> Joe Doe</strong>
When I display the field on the ASP page it shows as  Hello I am <strong> Joe Doe</strong>
Instead of making the name 'blank'  like:    Hello I am  Joe Doe

How can I display the text correctly and not the code 'behind'  it ?
0
Comment
Question by:amucinobluedot
  • 7
  • 4
  • 3
  • +1
16 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 41794312
It sounds like you are escaping the HTML before you send it to the browser.  How are you emitting that text onto the browser?
0
 

Author Comment

by:amucinobluedot
ID: 41794328
I am using a stored procedure. Attached is the code for that page.  

This is the portion of the SP that selects the notes that are displayed:

  STUFF( (SELECT Comments + ' | ' 
                             FROM casecomments b
                              WHERE  b.caseid = a.id
                             ORDER BY lastupdate
                             FOR XML PATH('')) , 
                            1, 0, '') AS casenotes,

Open in new window

code.txt
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 41794354
Try:

Response.Write "Hello I am <strong> Joe Doe</strong>"

That should output the bold in that string
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 82

Expert Comment

by:hielo
ID: 41794399
In XML the less than, greater than, and ampersand characters have "special meaning", so they would need to be escaped if you wanted them as part of the data.  Your query has a "FOR XML" clause, so most likely  it is escaping the less and greater than symbols contained in the Comments field.

Try changing:
<%=(report_results.Fields.Item("casenotes").Value)%>

Open in new window


to:
<%= Replace(Replace(Replace(report_results.Fields.Item("casenotes").Value, "&lt;","<"),"gt;",">"),"<script","") %>

Open in new window

0
 
LVL 55

Accepted Solution

by:
Julian Hansen earned 250 total points
ID: 41794403
Sounds like your data is encoded in the database which means you have to decode it before sending to the browser
Example
Function HTMLDecode(html)
    html = Replace(html, "&quot;", Chr(34))
    html = Replace(html, "&lt;"  , Chr(60))
    html = Replace(html, "&gt;"  , Chr(62))
    html = Replace(html, "&amp;" , Chr(38))
    html = Replace(html, "&nbsp;", Chr(32))
    HTMLDecode = html
End Function

dim s
s = "&lt;strong&gt;Jon Doe&lt;/strong&gt;"
Response.Write HTMLDecode(s)
%>	

Open in new window

0
 

Author Comment

by:amucinobluedot
ID: 41794405
I got this error:

Microsoft VBScript runtime error '800a005e'

Invalid use of Null: 'Replace'

/bluedot/Intranet/reports/rp_all_01_results.asp, line 408
0
 

Author Comment

by:amucinobluedot
ID: 41794417
Julian,

How do I apply that function and I got this error:

Microsoft VBScript runtime error '800a005e'

Invalid use of Null: 'Replace'

/bluedot/includes/bdot/scripts.asp, line 428 

Open in new window


This is on the script's first line.  Some of the fields are null some have data.

I am trying to display the content with:

<%=HTMLDecode(report_results.Fields.Item("casenotes").Value)%>
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 41794424
sorry my last answer was incomplete, try this if only your code isn't encoded when you save it.

Response.Write Server.HTMLEncode( "Hello I am <strong> Joe Doe</strong>" )

If the data IS encoded, you'll have to manually decode it using the clean function I gave you awhile back
0
 

Author Comment

by:amucinobluedot
ID: 41794442
Big Monty:  I tried using the code we have to 'clean' (using in the other post) but the text still looks the same:


G-28, I-129 emailed to amucino'23@demo.com as PDF by Attorney Name. | &lt;p&gt;tseefe&lt;/p&gt; | &lt;p&gt;Please make sure you add comments to this case visible to both&lt;/p&gt; | &lt;p&gt;Add comments to this case here one visible indv not and low&lt;/p&gt; | &lt;p&gt;test&lt;/p&gt; | &lt;p&gt;test 2&lt;/p&gt; |
0
 
LVL 82

Expert Comment

by:hielo
ID: 41794443
If the field contains nulls, then use:
<%
If NOT IsNull(report_results.Fields.Item("casenotes").Value) Then
Response.Write( Replace(Replace(Replace(report_results.Fields.Item("casenotes").Value, "&lt;","<"),"gt;",">"),"<script","") )
End If
%>

Open in new window

0
 

Author Comment

by:amucinobluedot
ID: 41794451
Tried the above and still got error:

Microsoft VBScript runtime error '800a005e'

Invalid use of Null: 'Replace'

/bluedot/Intranet/reports/rp_all_01_results.asp, line 411

I also tried:

If NOT IsNull(report_results.Fields.Item("casenotes").Value) Then
HTMLDecode(report_results.Fields.Item("casenotes").Value)

and got the same above error.
0
 
LVL 82

Assisted Solution

by:hielo
hielo earned 250 total points
ID: 41794456
Regarding Julian's function do a null check within the HTMLDecode
Function HTMLDecode(html)
    HTMLDecode=""
   If NOT IsNull(html) Then
    html = Replace(html, "&quot;", Chr(34))
    html = Replace(html, "&lt;"  , Chr(60))
    html = Replace(html, "&gt;"  , Chr(62))
    html = Replace(html, "&amp;" , Chr(38))
    html = Replace(html, "&nbsp;", Chr(32))
    HTMLDecode = html
  End If
End Function

<%=HTMLDecode(report_results.Fields.Item("casenotes").Value)%>

Open in new window

0
 

Author Comment

by:amucinobluedot
ID: 41794458
PERFECT !  That addition worked. Thank you everyone!  I will go ahead and share the points I hope thats ok with everyone.
0
 

Author Closing Comment

by:amucinobluedot
ID: 41794461
Thank you !
0
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 41794493
How are you trying to apply it - what does your code look like?
You can see the code above working here
0
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 41794504
You are welcome.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
age from date of birth 4 51
Time Conversions...both ways 2 16
ASP/VB email question 4 46
Javascript Urgent help (Need help to disable event handler) 8 41
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question