Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

response.write and include file?

Posted on 2006-11-17
9
Medium Priority
?
257 Views
Last Modified: 2013-11-18
Hi,

I am trying to adapt a script which was originally used to see if an image name matches a variable within a specific folder, if it does then the image is displayed, if not then a default image is displayed.  I need to do a similar thing, but this time I am displaying different (html) text.  I thought about doing it with the html text in little include asp files but I am not sure if it works with the script.  Could someone take a look for me and advise.

<%
' See if there is a brand string in var level2 and that matches a brand description

Set fs=Server.CreateObject("Scripting.FileSystemObject")

if prodrs("p_level2") <> "" then
  if fs.fileexists(server.mappath("includes/" & server.urlencode(prodrs("p_level2")) & ".asp")) then
   response.write "<!-- #INCLUDE FILE=""includes/" & server.urlencode(prodrs("p_level2")) & ".asp"">"
else
   response.write "<!-- #INCLUDE FILE=""includes/default.asp"">"
end if
else
  response.write "<!-- #INCLUDE FILE=""includes/default.asp"">"
end if

set fs=nothing
%>

Many thanks,
Tony

0
Comment
Question by:Treder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
9 Comments
 
LVL 22

Expert Comment

by:WMIF
ID: 17967884
that will not work because includes are processed by the server before the asp code is processed.  depending on what is in the pages, it may work to do something like this.  the first one wont work though because of the asp code in the include statement

<%
' See if there is a brand string in var level2 and that matches a brand description

Set fs=Server.CreateObject("Scripting.FileSystemObject")

if prodrs("p_level2") <> "" then
  if fs.fileexists(server.mappath("includes/" & server.urlencode(prodrs("p_level2")) & ".asp")) then
%>
<!-- #INCLUDE FILE=""includes/" & server.urlencode(prodrs("p_level2")) & ".asp"">  <-------  no worky
<%
else
%>
<!-- #INCLUDE FILE=""includes/default.asp"">
<%
end if
else
%>
<!-- #INCLUDE FILE=""includes/default.asp"">
<%
end if

set fs=nothing
%>
0
 

Author Comment

by:Treder
ID: 17968143
Many thanks for the reply.

Yes, I read up a bit about the include processing.  Will give it a go and report back
0
 

Author Comment

by:Treder
ID: 17970912
I guess I could do something like this:

...
if prodrs("p_level2") = "producta" then %>

<td> product a text </td>

<%
else if prodrs("p_level2") = "productb" then
%>

<td> product b text </td>

<%
else
%>

<td> default text </td>

<%
end if


Would that be sensible??
set fs=nothing
%>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Accepted Solution

by:
Dany Balian earned 2000 total points
ID: 17971564
or you can do sthg like
...
select case prodrs("p_level2")

case "producta"
%>
<td> proudct a text </td>
<%
case "productb"
%>
<td> proudct b text </td>
<%
case "productc"
%>
<td> proudct c text </td>
<%
case else
%>
<td> other product text</td>
<% end select %>


or even without opening a series of <% %>

<%
Select case prodrs("p_level2")
case "producta": response.write ("<td>product a text</td>")
case "productb": response.write ("<td>product b text</td>")
case "productc": response.write ("<td>product c text</td>")
case else: response.write ("<td>other product text</td>")
end select
<%>


same goes if you want to use nested IF statements
<%
if prodrs("p_level2")="producta" then
  response.write ("<td>product a text</td>")
elseif prodrs("p_level2")="productb" then
  response.write ("<td>product b text</td>")
elseif prodrs("p_level2")="productc" then
  response.write ("<td>product c text</td>")
else
  response.write ("<td>other product text</td>")
end if
%>

hope this helps..

cheers

dan
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 17971573
please note that in your case you have one missing end if

the syntax of if statements is:

if condition then
'statement1
elseif condition2 then     'else and if are attached together no space between them
'statement2
elseif condition3 then
'statement3
else
'statement 4
end if

cheers,

dan
0
 

Author Comment

by:Treder
ID: 18485660
Dear hongjun,

Either you guys are ultra-tidy or I am a bit slack...  I have not yet had a chance to look at all the suggested solutions, which of course I need to do before I can allocate points appropriately.

I am sorry to the posters if they feel I have taken too long and I really appreciate the ideas put forward.

I will allocate points now based on a brief run through.

Many thanks all,
Tony
0
 

Author Comment

by:Treder
ID: 18485692
Sorry - that will teach me... In my haste I thought this was the cleanup of a newer post.  

... please ignore my previous post.
0

Featured Post

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.

Question has a verified solution.

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

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

662 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