我想用<!--#include file=""-->插入一个文件。但这个文件名不是固定的,<!--#include file="<%=ess%>"-->这样写后,iis报错。请问这个问题该如何解决?
---------------------------------------------------------------
that is true, ASP does the include first, then do the scripting, try
<iframe frameborder=0 src=="<%=ess%>"></iframe>
or you can always read the file and output there
---------------------------------------------------------------
解析顺序问题!无法解决!重新设计程序!
---------------------------------------------------------------
the answer is no, if you use < !--#include ....-->
but if you use IIS5, you can try to use something like
if condition = true then
Server.Execute "file1.asp"
else
Server.Execute "file2.asp"
end if
or use ScriptControl and evaluate the included file yourself conditionally
---------------------------------------------------------------
同意“ saucer(思归)”的想法;另外,如果真要用你这个方法的话,你可以在“include file="<%=ess%>"-->”所包含的文件中使用“Session”变量,在此变量中包含文件名,以根据不同的情况使用不同的包含文件。
你试试吧。
Good Luck!
---------------------------------------------------------------
include里不能使用变量,所以只好用其它的办法了:
if 条件 then
<!--#include file="1.asp"-->
else
<!--#include file="2.asp"-->
end if
或者用CASE来加以判断
---------------------------------------------------------------
包含文件代码<!--#include file=""-->始终运行在asp代码的前面,当然就会报错
---------------------------------------------------------------
include里不能使用变量,同意 meizz(梅花雨) 的方法
---------------------------------------------------------------
meizz(梅花雨) 兄
你的好像也有问题啊!Include不能写到<%%>里面的.
<%
if 条件 then
%>
<!--#include file="1.asp"-->
<% else %>
<!--#include file="2.asp"-->
<% end if %>
---------------------------------------------------------------
补充.
我到是觉得你应该把变量先写到一个asp文件中.然后在其他文件里面调用他.这样不就好了么?可能语言表达有问题.用的例子说明一下.
例子:
inculde.asp
<%
sub info()
判断
end sub
sub theme()
判断
end sub
%>
index.asp
<#--include file="inculde.asp"-->
<%
代码
call info()
代码判断
if 条件 then
call theme()
else
输出
end if
%>
就是分别调用.这样应该可以实现你的目的吧!
---------------------------------------------------------------
asp中的include跟c中的include差不多,是预先处理的,也就是说,在脚本未得到解释前先处理的,这样你的程序当然得不到执行了,所以产生了找不到包含文件的错误
---------------------------------------------------------------
我使用过大猫的方法应该可以,而且至少都是在asp3.0的标准
kingljx
qq:4863198
msn:kingljx@hotmail.com
---------------------------------------------------------------
对asp 3.0增加了server.excute的方法,这种方法在以前的版本中是不存在的。
<include file="<%=var%>.asp">这种用法是不行的。
凡是include语句,都不可以使用asp变量,参见《ASP宝典》。
但你一定要用include,也是有方法的:
思路:把<include file="<%=var%>.asp">整个作为一个字符串变量,然后自己写需要显示的asp程序。
比如需要动态显示、含有include的文件是MyProduct.asp
那么在转到MyProduct.asp之前,我在另一个文件中写入:
如:
<%
写入文件名变量
FilePath="../viewreports/info"&pid&".htm"
''将文件写入myproduct.asp以供调用
set fs=server.CreateObject("Scripting.FileSystemObject")
AbPath=Server.MapPath("/mysite/viewreports/MyProduct.asp")
set ts=fs.CreateTextFile(AbPath,true)
TxtStr="<html><body><table><!--#include File=""" & FilePath & """ --></table></body></html>"
ts.writeline TxtStr
ts.close
set ts=nothing
set fs=nothing
''将页面转向myproduct.asp
response.redirect "/mysite/viewreports/MyProduct.asp"
end if
%>
不知道有没有帮助?
 |