Conditional Includes

T

Thomas

Hi,

Will this work in asp 3.0:

If True Then
<!-- #include file="test1.asp" -->
Else
<!-- #include file="test2.asp" -->
End If

- Thomas
 
K

Kris Eiben

Yes, it will work, assuming you start and end your ASP blocks
correctly -- though probably not in the way you expect. Both files will
be included, but only the one that matches the condition will be used.
 
T

TomB

Yes and no.
The include files are processed first, so the contents of test1.asp and
test2.asp will be plugged in. Then your if/then will be processed.

Probably a better solution would be to wrap the contents of test1.asp in a
subroutine, and test2.asp in a separate subroutine.

Example.

test1.asp

Sub test1sub()
'code from test1.asp
End Sub

test2.asp

Sub test2sub()
'code from test2.asp
End Sub

page.asp
<!--#include file="test1.asp"-->
<!--#include file="test2.asp"-->

If True then
Call test1sub
else
Call test2sub
 
T

Thomas

So

if test1.asp contains this line:
response.write "Hello 1"

and if test2.asp contains this line:
response.write "Hello 2"

The result of

will allways be

Hello 1
Hello 2

- Thomas
 
T

TomB

No. The processor would convert it to
If True Then
response.write "Hello 1"
Else
response.write "Hello 2"
end if

which would result in
Hello 1

So, it basically does what you want (presumably) but you can run into
conflicts.
If test1.asp contains
Dim x
x=1
and test2.asp contains
Dim x
x=2
then you've "redimmed" and will get an error. However, if they are in
subroutines, the scope of x is within the subroutine so you won't have a
conflict.
 
A

Alex Goodey

No the reult will alwasy be

Hello 1

doing

If True Then
<!-- #include file="test1.asp" -->
Else
<!-- #include file="test2.asp" -->
End If

If True Then
response.write "Hello 1"
Else
response.write "Hello 2"
End If

is exactly the same as doing
 
T

TomB

http://www.aspfaq.com/show.asp?id=2042


TomB said:
No. The processor would convert it to
If True Then
response.write "Hello 1"
Else
response.write "Hello 2"
end if

which would result in
Hello 1

So, it basically does what you want (presumably) but you can run into
conflicts.
If test1.asp contains
Dim x
x=1
and test2.asp contains
Dim x
x=2
then you've "redimmed" and will get an error. However, if they are in
subroutines, the scope of x is within the subroutine so you won't have a
conflict.


in
 
V

Vilmar Brazão de Oliveira

in my routines this runs well like:
<%
if Session("logado") <> "sim" then
'Rotina de verificação de sessão do usuário só funciona dentro das
tags<body></body>
%>
<!--#include file="controle_sessao.asp" -->
<%End If%>
bye

--

««««««««»»»»»»»»»»»»»»
Vlmar Brazão de Oliveira
Desenvolvimento Web
HI-TEC
 
T

Turkbear

in my routines this runs well like:
<%
if Session("logado") <> "sim" then
'Rotina de verificação de sessão do usuário só funciona dentro das
tags<body></body>
%>
<!--#include file="controle_sessao.asp" -->
<%End If%>
bye

What most of the responses want to emphasise is that, even though the logic will work and only the 'correct' page will
be displayed, all of the includes will be read and processed before anything else happens...If those pages are large
and/or contain lots of processor intensive or memory heavy stuff, you can run into real resource depletion problems.

The faq citation from Tom B :
http://www.aspfaq.com/show.asp?id=2042

has, at the end, a discussion of using Server.Execute - It will help, if it can be employed in your situation.

hth
 
B

Brynn

If the content in test1.asp and test2.asp are not dependent on the
rest of the page ... I would consider Server.Execute in your if/then
... that way the entire pages code from the files won't be pulled in
... only what is executed.




Hi,

Will this work in asp 3.0:

If True Then
<!-- #include file="test1.asp" -->
Else
<!-- #include file="test2.asp" -->
End If

- Thomas

I participate in the group to help give examples of code. I do not guarantee the effects of any code posted. Test all code before use!

Brynn
www.coolpier.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,821
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top