Server-Side Includes

Discussion in 'ASP General' started by RN1, Dec 16, 2007.

  1. RN1

    RN1 Guest

    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?
     
    RN1, Dec 16, 2007
    #1
    1. Advertising

  2. "RN1" <> wrote in message
    news:...
    > 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.



    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Dec 16, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William F. Zachmann
    Replies:
    6
    Views:
    2,639
    William F. Zachmann
    Oct 25, 2005
  2. Martin Olson
    Replies:
    1
    Views:
    572
    Martin Olson
    Dec 16, 2005
  3. David Dorward

    Re: Server-Side Includes

    David Dorward, Jul 20, 2003, in forum: HTML
    Replies:
    0
    Views:
    362
    David Dorward
    Jul 20, 2003
  4. Adrienne

    Re: Server-Side Includes

    Adrienne, Jul 21, 2003, in forum: HTML
    Replies:
    1
    Views:
    396
    Rob McAninch
    Jul 23, 2003
  5. Paul F. Johnson

    Server side includes

    Paul F. Johnson, Sep 5, 2003, in forum: HTML
    Replies:
    9
    Views:
    508
    superdairyboy
    Sep 11, 2003
Loading...

Share This Page