Calling include files in response.write, or do while loops

Discussion in 'ASP General' started by .Net Sports, Mar 15, 2005.

  1. .Net Sports

    .Net Sports Guest

    I want to include some asp if statements inside a do until loop,
    predicated on the recordset going until EOF. I do not have any < % %>
    delimiters inside the include file. The below doesnt show the character
    I want to display:

    <% do until rs.eof
    response.write rs("position")
    <!-- #include file="inc_.asp" -->
    loop %>

    ...while hard coding the character with another response.write statement
    will.

    Thanks for any insights
    ..net sports
    .Net Sports, Mar 15, 2005
    #1
    1. Advertising

  2. Well, first off, I don't see an rs.movenext, nor do you break out of <% %>
    to call the #include file (<!--#include does not belong inside <% %>
    delimiters!). See what happens when you change it to:

    <%
    do WHILE NOT rs.eof
    response.write rs("position")
    %>
    <!-- #include file="inc_.asp" -->
    <%
    rs.movenext
    loop
    %>

    Next, why not #include a file once (or not at all), and have a function.
    Then not only will you avoid having this #include file referenced 8000
    times, you can also make the function respond directly to differences
    between rows in your resultset. Much smoother architecture that way...

    e.g.

    inc_.asp

    <%
    function writeCharacter()
    response.write "bleh"
    end function
    %>

    Now your loop becomes:

    <%
    do while not rs.eof
    response.write "<br>" & rs("position")
    writeCharacter()
    rs.movenext
    loop
    %>

    I don't see the point of repeating an #include directive n times with the
    same file, it doesn't seem to make sense to me at all.

    --
    Please post DDL, sample data and desired results.
    See http://www.aspfaq.com/5006 for info.




    ".Net Sports" <> wrote in message
    news:...
    > I want to include some asp if statements inside a do until loop,
    > predicated on the recordset going until EOF. I do not have any < % %>
    > delimiters inside the include file. The below doesnt show the character
    > I want to display:
    >
    > <% do until rs.eof
    > response.write rs("position")
    > <!-- #include file="inc_.asp" -->
    > loop %>
    >
    > ..while hard coding the character with another response.write statement
    > will.
    >
    > Thanks for any insights
    > .net sports
    >
    Aaron [SQL Server MVP], Mar 15, 2005
    #2
    1. Advertising

  3. > <%
    > do WHILE NOT rs.eof
    > response.write rs("position")
    > %>
    > <!-- #include file="inc_.asp" -->
    > <%
    > rs.movenext
    > loop
    > %>


    The #include won't be performed N times. It will be performed once. It's a
    textual include, not an ASP script command. Nevertheless the point about not
    doing this (for other reasons) is well taken.
    Jonathan Dodds, Mar 17, 2005
    #3
  4. Right, important distinction. The file isn't #included n times, but the
    code inside is still processed by the ASP engine n times (regardless of
    whether it has ASP code or not). If it contains HTML, then that part it is
    rendered by the browser n times.

    Try this example:

    <% for I = 1 to 5 %>
    <!--#include file=bar.asp-->
    <% next %>

    Bar.asp:

    <% response.write i & "<p>" %>

    All in all, probably not *that* much different from calling a function, but
    much more difficult to manage, IMHO.





    On 3/16/05 11:11 PM, in article ,
    "Jonathan Dodds" <NO_REPLY> wrote:

    >> <%
    >> do WHILE NOT rs.eof
    >> response.write rs("position")
    >> %>
    >> <!-- #include file="inc_.asp" -->
    >> <%
    >> rs.movenext
    >> loop
    >> %>

    >
    > The #include won't be performed N times. It will be performed once. It's a
    > textual include, not an ASP script command. Nevertheless the point about not
    > doing this (for other reasons) is well taken.
    >
    >
    Aaron [SQL Server MVP], Mar 17, 2005
    #4
    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. Charles A. Lackman
    Replies:
    2
    Views:
    8,002
    Charles A. Lackman
    Jan 11, 2006
  2. Replies:
    1
    Views:
    832
  3. =?Utf-8?B?TWFuaXNoIFNhd2ppYW5p?=

    Using loops <TD><%= Response.write("Data")%> </TD>...

    =?Utf-8?B?TWFuaXNoIFNhd2ppYW5p?=, Oct 14, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    672
    sloan
    Oct 15, 2006
  4. Andreas Bogenberger
    Replies:
    3
    Views:
    906
    Andreas Bogenberger
    Feb 22, 2008
  5. Me
    Replies:
    2
    Views:
    244
Loading...

Share This Page