|
-
Oct 16th, 2001, 11:08 AM
#1
Thread Starter
Frenzied Member
ASP/VBS: Alternatives to #include
Okay, this is very hard to explain, so bare with me.
Currently I have a block in my ASP that looks like this:
Code:
<div class="PanelSpace">
<div class="Panel" id="Panel0">
<!---#include virtual="/test/alpha.inc"-->
</div>
<div class="Panel" id="Panel1">
<!---#include virtual="/test/beta.inc"-->
</div>
<div class="Panel" id="Panel2">
<!---#include virtual="/test/gamma.inc"-->
</div>
<div class="Panel" id="Panel3">
<!---#include virtual="/test/delta.inc"-->
</div>
</div>
I am wanting to create a loop in the ASP that will accomplish the same thing.
Code:
<div class="PanelSpace">
<%
for currPanel = 0 to UBound(PanelNames, 1)
%>
<div class="Panel" id="Panel<%=currPanel%>">
<%'Panels Source .inc file should be accessed here%>
</div>
<%
next 'Panel
%>
</div>
I can't use the #include directive since that will get processed before the ASP will. I've tried Server.Execute, but I need the .inc to be able to use the same embedded ASP techniques that this page is using, and to be able to call on variables defined here.
Any ideas? Any questions?
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Oct 16th, 2001, 11:20 AM
#2
Unfortunately you can't use a variable name as an include file, because the server doesn't know the variable state at that time. You would have to use Select Case statement to make an include:
Code:
<%For currPanel = 0 to UBound(PanelNames, 1)%>
<% Select Case currPanel%>
<% Case 0: %><!--#include file="File1.asp"-->
<% Case 1: %><!--#include file="File2.asp"-->
<% End Select%>
<%Next%>
In ASP 3.0 you can fake the include by using Server.Execute
With Server.Execute, the ASP page called is loaded, run, and then unloaded. This is great if you have some procedural ASP code you want to execute, but oftentimes developers fill #include files with commonly used functions. Assume that A.asp contains the code: Server.Execute("B.asp"). Because of the nature of Server.Execute, A.asp can't call any functions declared in B.asp! For that reason, Server.Executes are rarely useful for dynamic includes.
-
Oct 16th, 2001, 11:54 AM
#3
Thread Starter
Frenzied Member
Okay, don't ask me why... I went over the idea of case switches so many times in my head and determined that it would not work.
Anyway, this works.
Code:
<script type="text/javascript">
if (DynamicContent) {
document.writeln("<div class=\"PanelSpace\">");
}
</script>
<%for currTab = 0 to UBound(TabNames, 1)%>
<script type="text/javascript">
if (DynamicContent) {
document.writeln("<div class=\"Panel\" id=\"Panel<%=currTab%>\">");
}
else {
document.writeln("<a id=\"aTable<%=currTab%>\" name=\"aTable<%=currTab%>\"></a>");
}
</script>
<%Select Case currTab%>
<%Case 0:%><!---#include virtual="/test/alpha.inc"-->
<%Case 1:%><!---#include virtual="/test/beta.inc"-->
<%Case 2:%><!---#include virtual="/test/gamma.inc"-->
<%Case 3:%><!---#include virtual="/test/delta.inc"-->
<%End Select%>
<script type="text/javascript">
document.writeln("</div>");
</script>
<%next 'currTab%>
<script type="text/javascript">
if (DynamicContent) {
document.writeln("</div>");
}
</script>
Thanks.
As an aside, there are three different ASP formatting techniques in this thread so far. I'm still not decided on which I like best.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|