Server-Side Includes

R

RN1

The book I am referring to learn ASP states the following about server-
side includes:

==============================================
The code in a server-side include file is inserted into the pages that
use it BEFORE the page's ASP code is evaluated. This means that you
can put ASP code inside the include file, and it will be executed like
it was part of the page that includes it. On the other hand, it means
that you cannot use ASP to determine which page to include.
==============================================

But as opposed to the last line in the above para, the following code
makes use of ASP to determine which page to include:

<%
Dim intA,intB

intA=5
intB=6

If(intA>intB) Then
%>
<!-- #include file="File1.inc"-->
<%
Else
%>
<!-- #include file="File2.inc"-->
<%
End If
%>

File1.inc has only one line - This is File1.
Similarly, File2.inc also has only one line - This is File2.

Now since the If condition in the above code evaluates to False,
File2.inc gets included & hence the browser displays

This is File2.

But if I change the value of intA to, say, 10, so that the If
condition evaluates to True, then File1.inc gets included &
consequently the browser displays

This is File1.

So isn't the last line in the above para which I cited from the ASP
book wrong?
 
A

Anthony Jones

RN1 said:
The book I am referring to learn ASP states the following about server-
side includes:

==============================================
The code in a server-side include file is inserted into the pages that
use it BEFORE the page's ASP code is evaluated. This means that you
can put ASP code inside the include file, and it will be executed like
it was part of the page that includes it. On the other hand, it means
that you cannot use ASP to determine which page to include.
==============================================

But as opposed to the last line in the above para, the following code
makes use of ASP to determine which page to include:

<%
Dim intA,intB

intA=5
intB=6

If(intA>intB) Then
%>
<!-- #include file="File1.inc"-->
<%
Else
%>
<!-- #include file="File2.inc"-->
<%
End If
%>

File1.inc has only one line - This is File1.
Similarly, File2.inc also has only one line - This is File2.

Now since the If condition in the above code evaluates to False,
File2.inc gets included & hence the browser displays

This is File2.

But if I change the value of intA to, say, 10, so that the If
condition evaluates to True, then File1.inc gets included &
consequently the browser displays

This is File1.

So isn't the last line in the above para which I cited from the ASP
book wrong?

According the what the book says your page will look like this before it is
parsed and executed as an ASP page:-

<%
Dim intA,intB

intA=5
intB=6

If(intA>intB) Then
%>
This is File1.
<%
Else
%>
This is File2.
<%
End If
%>

As you can see both includes have been added. Try changing the content of
file2 to this:-

<%
End If
%>
This is File2.
<%
If False Then
%>

The resulting file before parsing becomes:-

<%
Dim intA,intB

intA=5
intB=6

If(intA>intB) Then
%>
This is File1.
<%
Else
%>

<%
End If
%>
This is File2.
<%
If False Then
%>
<%
End If
%>

The resulting output is:-

This is File1.
This is File2.
 

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
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top