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

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?
LVL 1
WeaveDaddyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aprestoCommented:
<%
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
eliavmCommented:
Try adding <%@language=VBScript Codepage=1255%> to the top of the file.

Please write the full source of this asp file.

0
GawaiCommented:
can u post ur ful code here ?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

aprestoCommented:
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
WeaveDaddyAuthor Commented:
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
aprestoCommented:
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
WeaveDaddyAuthor Commented:
LEN = 1524

Server.HTMLencode does not work

0
John_LennonCommented:
what about
<% if len(Country.Fields.Item("CountryBackground").Value) > 0 then %>
<%=(Country.Fields.Item("CountryBackground").Value)%>
<% end if %>
see if this helps you
0
John_LennonCommented:
sorry, @apresto write my solution first
0
WeaveDaddyAuthor Commented:
seems like the len statement should work but it does not
0
John_LennonCommented:
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
aprestoCommented:
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
WeaveDaddyAuthor Commented:
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
eliavmCommented:
try ....

<%
tmp=Country.Fields.Item("CountryBackground").Value
if tmp<>"" then
      Response.Write tmp
end if
%>
0
John_LennonCommented:
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
WeaveDaddyAuthor Commented:
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
eliavmCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WeaveDaddyAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.