This question already has an answer here:
- ASP 3.0 - Server.Execute Problems: Suffering from “ASP Amnesia” 3 answers
I'm using IIS 6, and created Two ASP 3.0 files: -Main.asp -Colors.asp
Main.asp
<%
If sColor = true then
Server.Execute "Colors.asp"
End If
'If sColor is true, Pops over to Colors.asp
'Then pops right back over to here again
'Once back here again, it has no idea what
'sRed or sBlue was at all...it's as if has
'been "blank slated"...sRed? Who the heck is sRed?
If sRed then
Response.Write "Color is Red"
End If
'Does not work...skips right over...
'Who is sRed? What is sRed?
'Oh well, keep on truckin'
%>
Colors.asp
<%
Dim sRed
sRed = instr(sString, "Red") >0
Dim sBlue
sBlue = instr(sString, "Blue") >0
Dim sGreen
sGreen = instr(sString, "Green") >0
%>
If one were to go into the Colors.asp file above and modify/append it to read as follows:
<%
Dim sRed
sRed = instr(sString, "Red") >0
Dim sBlue
sBlue = instr(sString, "Blue") >0
Dim sGreen
sGreen = instr(sString, "Green") >0
If sRed then
Response.Write "Color is Red"
End If
%>
One would receive a screen with "Color is Red" when sColor was true over at Main.asp and sString contained "Red." So I know she's getting over there, and also returning back over to Main.asp...but somehow she has no clue about those variables: sRed, sBlue, or sGreen that were dimmed over at Colors.asp. Once she gets back over to Main.asp she's clueless.
What gives? Why does she have ASP Amnesia once she gets back to Main.asp after having just been over at Colors.asp?
Edit
Dear YougoTiger,
I did what you suggested (I think) in Main.asp:
If sColor = true then
Server.Execute "Colors.asp"
If sRed then
Response.Write "Color is Red"
End If
End If
Nothing...still has ASP Amnesia- sRed Who?
Edit 2
Dear Bitwize,
I'm using Server.Execute instead of #include in order to free up the server. As you know #includes always get handled first in ASP, regardless of whether they are inside an If
block. I'm basically trying to do dynamic server-side includes by way of Server.Execute, which can in fact be placed within an If
block according to Microsoft:
Microsoft Support - Using the Server.Execute Method
The New ASP 3.0 Server Methods (Note: this is was originally http://www.15seconds.com/issue/010220.htm but that site is gone, the link is now a redirect to a numeric domain. Feel free to do your own search for the article by Paul Litwin and update this link if you can find it.)
A Look at ASP 3.0
The low-down on #includes
I still needing help with this, or a better explanation as to what is going on in my particular case. I've got a lot of dimmed variables over in that Color.asp file that I don't want the server to bother with if sColor=False.