Solved

response.write and include file?

Posted on 2006-11-17
9
249 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
  • 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
LVL 11

Accepted Solution

by:
Dany Balian earned 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Classic ASP application Will support SQL 2014 5 94
SQL to update characters in table column 6 147
If-Then-Else ASP problem 6 67
If condition on Html with Asp 11 27
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

839 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