Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

response.write include file 1

Status
Not open for further replies.

thompom

Technical User
Dec 4, 2006
395
GB
hi,

am having trouble getting include pages to be dynamically
written to the page using response.write
my plan is to have the include pages in fields in a db so
a user can change the content of the page by changing the database fields

my question is, why does this work-
Code:
<div class="leftslot">
<!--#include file=test.asp-->
</div>

and this one doesnt?
Code:
<%x_leftslot = "<!--#include file=test.asp-->"%>
<div class="leftslot">
<%Response.Write x_leftslot%>
</div>
</div>
 
have just read this

"You cannot open or close a script delimiter in an INC file"

is this why i cant write this line using asp?
 
The includes are inserted before the ASP is processed, where you're attempting to include AFTER the ASP is run.

Lee
 
thanks for your reply
is there any way to achieve this? -
or is there a different way of including asp pages within asp pages

how would you do this?
 
What exactly is the goal? Is it to have a single page that displays different content depending on values from a database?
 
yeah - i have been building my pages 1by1 for a long time
but i thought why not have a table in a database
and a css layout page which is filled by .writing
the links from a database.

this works fine for text/images etc - but what if i want to put whole asp scripts between these div tags?
 
...ultimately the page will be managed by a non technical user who will have a layout of the page and be able to 'plugin' these scripts
 
any ideas anyone?
have a page made of div tags and want to be able to insert
asp pages between tags using a database.
should the question be, is there anyway of loading the asp before the html?

any ideas welcome
 
I think that either this line is out of context, or the author was not as good as they think they were:
"You cannot open or close a script delimiter in an INC file"

You can put anything you want in an include file. Basically the way this works is that when you have include files, the engine takes the file that is being requested and goes through and inserts the content of all of the included files, basically creating one very large script. Only after it has replaced all the includes with the contents of their file does it begin to execute anything.

So, for example:
Code:
[b]Sample.asp[/b]
<%
Response.Write "A"

Response.Write "B"

Response.Write "C"
%>
will output exactly the same as:
Code:
[b]A.asp[/b]
<% Response.Write "A" %>

[b]B.asp[/b]
<% Response.Write "B" %>

[b]C.asp[/b]
<% Response.Write "C" %>

[b]Sample.asp[/b]
<!--#INCLUDE File=A.asp-->
<!--#INCLUDE File=B.asp-->
<!--#INCLUDE File=C.asp-->

The reason your example above didn't work is because includes have to be placed outside of the ASP tags. What you did was to create a string in ASP that had the Include text in it. Since all of the includes are resolved before the code starts executing, you cannot use code to dynamically create an include.

If the data is actually in the database, you don't need an include file to retrieve and display it. If your trying to move some of that logic away from your output code you could put the database call in a separate function and have it build the output that belongs in that section. you could even place tat function itself in an include file.

 
tarwn - thanks for your reply

can you tell me how you would include the following
asp page dynamically

have changed my html to .write statements


Code:
<%Set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str

countsql = "SELECT count(stock.make) AS makecount, make.make, make.makeid "_
& "FROM stock "_
& "INNER JOIN make on make.makeid = stock.make "_
& "GROUP BY makeid"

Set rsmakecount = Server.CreateObject("ADODB.Recordset")
rsmakecount.CursorLocation = 3
rsmakecount.Open countsql, conn, 1, 2 

response.Write("<table border=0 cellspacing=0 cellpadding=2><tr> <td colspan=2><span class=stockhead>Quick</span><span class=finder>Finder&#8482;</span><img src=images/quicklogo2.gif alt=quickfinder width=39 height=21></td></tr>")
x_makecount=0
 Do While (Not rsmakecount.Eof) 
x_makeid = rsmakecount("makeid")
x_makequick = rsmakecount("make")
x_makecount = rsmakecount("makecount")

response.Write("<tr><td >")
response.Write "<a href=3coltemp.asp?pagesetupid=2&x_Make=" & Server.URLEncode(x_makeid) & "&z_Make==,','><span class=quickfind>" & (x_makequick) & "</span></a></td><td ><span class=quickfind>("& (x_makecount) & ")</span></td></tr>"
    
'end if
rsmakecount.MoveNext
x_counttotal=x_counttotal+x_makecount
Loop

rsmakecount.close
conn.Close
Set conn = Nothing
response.Write("<tr><td><a href=3coltemp.asp?pagesetupid=2&cmd=reset><span class=quickfindall>Show All>></span></a></td><td><a href=3coltemp.asp?pagesetupid=2&cmd=reset><span class=quickfindall>(" & (x_counttotal) & ")</span></a></td> </tr>")
response.Write("</table>")%>
 
use an IF... THEN construct

Code:
<%if blah = something then%>
<!-- include virtual="/thispage.asp" -->
<%else%>
<!-- include virtual="/thisotherpage.asp" -->
<% end if%>

or a select case of course

make sure that any shared variables from the includes are declared in the including page

OR

provided your includes don't have any ASP code in them, I use a simple script to read a texfile then stream it back to the browser
Code:
Sub StreamText(TextFileName)
' read in a file and stream it out to the browser
Dim objFSO, objTextFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(Server.MapPath(TextFileName))

Do While Not objTextFile.AtEndOfStream
	Response.Write objTextFile.ReadLine  & vbCrLf  '& "<BR>"
Loop
objTextFile.Close
Set objTextFile = Nothing
Set objFSO = Nothing
End Sub
then you can use

Code:
strPageName = "something"
<%StreamText(strPageName)%>


Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
chris - thanks so much for your reply

however it is the asp pages that i am having trouble including.
is the Only answer to have all scripts on one page
and to use them only if the database values match
using a case statement.
i was trying to make my layout page clean and simple
and to reuse it for many pages of the site.

example

main layout page
rspage("leftslot1")record contains <!--#include file =autobase/quickfind.asp-->
Code:
x_leftslot1 = rspage("leftslot1")

  <div class="leftslot">
<%response.write (x_leftslot1)%>
  </div>

quickfind.asp include file

[code
<%Set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str

countsql = "SELECT count(stock.make) AS makecount, make.make, make.makeid "_
& "FROM stock "_
& "INNER JOIN make on make.makeid = stock.make "_
& "GROUP BY makeid"

Set rsmakecount = Server.CreateObject("ADODB.Recordset")
rsmakecount.CursorLocation = 3
rsmakecount.Open countsql, conn, 1, 2

response.Write("<table border=0 cellspacing=0 cellpadding=2><tr> <td colspan=2><span class=stockhead>Quick</span><span class=finder>Finder&#8482;</span><img src=images/quicklogo2.gif alt=quickfinder width=39 height=21></td></tr>")
x_makecount=0
Do While (Not rsmakecount.Eof)
x_makeid = rsmakecount("makeid")
x_makequick = rsmakecount("make")
x_makecount = rsmakecount("makecount")

response.Write("<tr><td >")
response.Write "<a href=3coltemp.asp?pagesetupid=2&x_Make=" & Server.URLEncode(x_makeid) & "&z_Make==,','><span class=quickfind>" & (x_makequick) & "</span></a></td><td ><span class=quickfind>("& (x_makecount) & ")</span></td></tr>"

'end if
rsmakecount.MoveNext
x_counttotal=x_counttotal+x_makecount
Loop

rsmakecount.close
conn.Close
Set conn = Nothing
response.Write("<tr><td><a href=3coltemp.asp?pagesetupid=2&cmd=reset><span class=quickfindall>Show All>></span></a></td><td><a href=3coltemp.asp?pagesetupid=2&cmd=reset><span class=quickfindall>(" & (x_counttotal) & ")</span></a></td> </tr>")
response.Write("</table>")%>
[/code]

this is just an example as i have more complex asp
pages that i want to 'include' from a database.
if im not making sense let me know!

 
It wasn't necessary to change all of your HTML to Write statements, even included ASP files can break out into HTML.

In your previous post you are still trying to write your include statement from ASP, which isn't going to work since code is executed after all of the includes have been resolved.

You cannot dynamically write an include from ASP, as it will not be processed as an include.

Referring to the post after my previous post, you could surround that code in a Function declaration and include the file at any point. Then when you need that section displayed simply call the Function.

Code:
<%

Sub DisplayMake
   Set conn = Server.CreateObject("ADODB.Connection")
   conn.Open xDb_Conn_Str

   countsql = "SELECT count(stock.make) AS makecount, make.make, make.makeid "_
   & "FROM stock "_
   & "INNER JOIN make on make.makeid = stock.make "_
   & "GROUP BY makeid"

   '...
   '...

   response.Write("</table>")%>
End Sub

Then to include this section:
Code:
<%
'some random ASP
'some random ASP

%><!--#INCLUDE FILE=filename.asp--><%

If SomeCondition = True Then
   DisplayMake
End If
%>

You could just as easily use a Case statement to determine which function or sub to call, provided the code has been included.

 
many thanks tarwn - graffiti is a great idea, hope SG1 is good
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top