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!

Can Include statements be dynamic in asp

Status
Not open for further replies.

aceman25

Programmer
Jul 27, 2001
6
0
0
CA
Is it possible to have dynamic include statements

I want to dynamically create an include statement.
Is this possible?
 
<%if this = true then%>
<!--#include file=&quot;myfile.asp&quot;-->
<%elseif that = true%>
<!--#include file=&quot;otherfile.asp&quot;-->
<%else%>
<!--#include file=&quot;yourfile.asp&quot;-->
<%end if%>

hth
leo leo
 
Actually I want to make the actual line
<!--#include file=&quot;myfile.asp&quot;-->, dynamic

like
Response.Write &quot;<!-- #include file=&quot;&quot;&quot; & RSBios(&quot;BIO&quot;) & &quot;&quot;&quot;-->&quot;

Is this possible?

aceman25
 
No this can't be done. The reason is because the include statement is executed before the ASP code is actually parsed. So by the time you come to the ASP logic, the file is already included. The only thing you can do is what vasah20 has suggested. What this actually results in, is all three files in vasah20's example are included but only one is effectively used. This is a limitation of ASP and there is no getting around it. Wushutwist
 
well , if you are only including text files or HTML, then you can use the FSO to 'dynamically' include files.

see faq333-504

for FSO information


leo leo
 
Attention!! This works only with Windows2000/IIS5.0

The way to do that is to use Server.Execute instead of
include. The reason is that the include directive is parsed before execution and even if you have things like that

<%if this = true then%>
<!--#include file=&quot;myfile.asp&quot;-->
<%elseif that = true%>
<!--#include file=&quot;otherfile.asp&quot;-->
<%else%>
<!--#include file=&quot;yourfile.asp&quot;-->
<%end if%>

it include all the files you mention (myfile.asp,otherfile.asp,yourfile.asp) not only what you wish.

With server.Execute it is possible to simulate your needs like so:

<%
if this = true then
Server.Execute &quot;myfile.asp&quot;
elseif that = true
Server.Execute &quot;myfile2.asp&quot;
else
Server.Execute &quot;myfile3.asp&quot;
end if
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top