?
Solved

response.write and include file?

Posted on 2006-11-17
9
Medium Priority
?
262 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
7 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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…
Suggested Courses

755 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