Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

IF...THEN...not working with html memo field ASP/VBscript/DW

Posted on 2006-04-25
18
Medium Priority
?
363 Views
Last Modified: 2009-12-16
Hi Everyone:

I have a memo field in an Access database that contains html and special characters. If I write the value to the html page, all is well using...

<%=(Country.Fields.Item("CountryBackground").Value)%>

If I try to do a conditional statement like:

<% if (Country.Fields.Item("CountryBackground").Value) <>"" then %>
<%=(Country.Fields.Item("CountryBackground").Value)%>
<% end if %>

I get nothing to display even though the value is not empty. My best guess is that is has something to do with html or special characters that use "&"

I tried things like escape, urlencode, server.htmlencode, len...I may not have done them correctly.

How do I check to make sure a value exists before displaying to the page if there are special characters?

Any ideas?
0
Comment
Question by:WeaveDaddy
  • 6
  • 4
  • 4
  • +2
18 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 16535487
<%
Response.Write "Field = " & Country.Fields.Item("CountryBackground").Value

if (Country.Fields.Item("CountryBackground").Value) <>"" then
   Response.write (Country.Fields.Item("CountryBackground").Value)
end if
%>

What is printed to the screen if you run this?  Field = ....
0
 

Expert Comment

by:eliavm
ID: 16535504
Try adding <%@language=VBScript Codepage=1255%> to the top of the file.

Please write the full source of this asp file.

0
 
LVL 20

Expert Comment

by:Gawai
ID: 16535531
can u post ur ful code here ?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 23

Expert Comment

by:apresto
ID: 16535560
try trimming:

If Trim(Country.Fields.Item("CountryBackground").Value) <> "" then...

OR Len it:

If Len(Trim(Country.Fields.Item("CountryBackground").Value)) > 0 then...

see if those work
0
 
LVL 1

Author Comment

by:WeaveDaddy
ID: 16535622
apresto:

the response write displays the paragraphs in the memo field, but the if then statement displays nothing...the memo field contains "&rsquo;s" and other html

Is this why?
0
 
LVL 23

Expert Comment

by:apresto
ID: 16535657
no, that shouldnt really have anything to do with it.  Try printing this to the screen:

Response.write "LEN = " & Len(trim(Country.Fields.Item("CountryBackground").Value))

it should give you the number of characters in the string, if this prints a number maybe we can use this method instead

did you say you have tried Server.HTMLencode( Country.Fields.Item("CountryBackground").Value )
0
 
LVL 1

Author Comment

by:WeaveDaddy
ID: 16535698
LEN = 1524

Server.HTMLencode does not work

0
 
LVL 6

Expert Comment

by:John_Lennon
ID: 16535701
what about
<% if len(Country.Fields.Item("CountryBackground").Value) > 0 then %>
<%=(Country.Fields.Item("CountryBackground").Value)%>
<% end if %>
see if this helps you
0
 
LVL 6

Expert Comment

by:John_Lennon
ID: 16535707
sorry, @apresto write my solution first
0
 
LVL 1

Author Comment

by:WeaveDaddy
ID: 16535719
seems like the len statement should work but it does not
0
 
LVL 6

Expert Comment

by:John_Lennon
ID: 16535744
what about
<% if not (isnull(Country.Fields.Item("CountryBackground").Value) or isempty(Country.Fields.Item("CountryBackground").Value)) then %>
<%=(Country.Fields.Item("CountryBackground").Value)%>
<% end if %>
0
 
LVL 23

Expert Comment

by:apresto
ID: 16535747
stick an ELSE block in there and print the LEN again, just to see what the hells going on - this is strange

@John_Lennon - No worries :o)
0
 
LVL 1

Author Comment

by:WeaveDaddy
ID: 16535779
It seems like after you do something conditional with the database value, the value exits or disappears because I have a normal write after the conditional write and the normal write no longer displays either...

<% if not (isnull(Country.Fields.Item("CountryBackground").Value) or isempty(Country.Fields.Item("CountryBackground").Value)) then %>
<%=(Country.Fields.Item("CountryBackground").Value)%>
<% end if %>


                    
<p><span class="style25"><%=(Country.Fields.Item("CountryBackground").Value)%></span></P>
0
 

Expert Comment

by:eliavm
ID: 16535807
try ....

<%
tmp=Country.Fields.Item("CountryBackground").Value
if tmp<>"" then
      Response.Write tmp
end if
%>
0
 
LVL 6

Expert Comment

by:John_Lennon
ID: 16535829
try this

strTemp = Country.Fields.Item("CountryBackground").Value
response.write strTemp & "<hr>"
if len(strTemp) > 0 then response.write "Has a value"
response.write len(strTemp) & "<br>"
if not isnull(strTemp) then response.write "has a value"
response.write isnull(strTemp) & "<br>"
if not isempty(strTemp) then response.write "has a value"
response.write isempty(strTemp) & "<br>"
if trim(strTemp) <> "" then response.write "has a value"
response.write trim(strTemp) & "<br>"

response.write "<hr>" & strTemp
at least one of this must be true
0
 
LVL 1

Author Comment

by:WeaveDaddy
ID: 16535878
eliavm:

that worked... I was trying to avoid response.write for other reasons and was trying to break the statement. If I break the ASP and try to then write the data value as
<%
tmp=Country.Fields.Item("CountryBackground").Value
if tmp<>"" then %>
      <%=(Country.Fields.Item("CountryName").Value)%>
<%end if
%>

I lose the value

guess I'll have to use response.write
0
 

Accepted Solution

by:
eliavm earned 500 total points
ID: 16535997
and how about breaking it like this ?

<%
tmp=Country.Fields.Item("CountryBackground").Value
if tmp<>"" then %>
 
     <%=tmp%>

<%end if%>


or

<%
tmp=Country.Fields.Item("CountryBackground").Value
if tmp<>"" then %>
 
     <% Response.write tmp%>

<%end if%>
0
 
LVL 1

Author Comment

by:WeaveDaddy
ID: 16536177
eliavm:
Both of your above scenarios work properly.

There's something definitely happening with trying to get the field value twice like below. Oh well...thanks everyone

<%
tmp=Country.Fields.Item("CountryBackground").Value
if tmp<>"" then %>
      <%=Country.Fields.Item("CountryName").Value%>
<%end if
%>
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

581 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