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. Advertisements

  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. Advertisements

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,816
    William F. Zachmann
    Oct 25, 2005
  2. Martin Olson
    Replies:
    1
    Views:
    645
    Martin Olson
    Dec 16, 2005
  3. Adrienne

    Re: Server-Side Includes

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

    Server side includes

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

    Server side includes

    Glen, Aug 10, 2005, in forum: HTML
    Replies:
    2
    Views:
    530
    Toby Inkster
    Aug 10, 2005
  6. Roderic Potter

    Trouble with server-side includes

    Roderic Potter, Aug 12, 2005, in forum: HTML
    Replies:
    9
    Views:
    495
    Neredbojias
    Aug 20, 2005
  7. Microsoft News

    Random Server Side Includes

    Microsoft News, Sep 17, 2003, in forum: ASP General
    Replies:
    3
    Views:
    225
    Chris Hohmann
    Sep 18, 2003
  8. Alan Howard
    Replies:
    8
    Views:
    311
    Alan Howard
    May 7, 2004
Loading...