SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    Watford, UK
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to include html files in ASP (similar to index.php?page=contact)

    Hi,

    I'm building a site which runs on 4 templates, each a different colour. I would like to pull in different content into each template using ASP.NET, similar to the php version of index.php?page=content.

    I've not programmed in ASP before so am hoping someone can either supply me with a script or point me in the right direction.

    cheers
    Last edited by andyrossy; Apr 5, 2005 at 06:52.

  2. #2
    SitePoint Member interpeo's Avatar
    Join Date
    Dec 2004
    Location
    Italy
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe this code would feet yor needs:

    <%
    ' ?content=first
    pageContent = Request.QueryString("content")

    'Check your content in order to include the right code
    SELECT CASE pageContent

    CASE "first"

    %> -> CLOSE ASP TAG!

    <!--#include file="first.html"-->

    <% CASE "second" %>

    <!--#include file="second.html"-->

    <% End Select %>

    That's it!

    interpeo

  3. #3
    SitePoint Member interpeo's Avatar
    Join Date
    Dec 2004
    Location
    Italy
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ... feeD your needs, better!

    Forgive my english!

    interpeo

  4. #4
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Argh! No!

    Do it like this:
    Code:
      <%
     ' You'll need to add stuff to check that the querystring matches a page name:
     Server.Execute(PageName & ".html")
     %>


    (PS. It's been around 2yrs since I've done ASP, so if it doesn't work, let me know!)

  5. #5
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I should have given you some info on what was wrong with the previous code. Basically, include pages should burn in hell! Yes, they are handy, but you should avoid using them! To counter the need to use include, Microsoft Introduced Server.Execute().

    The main problem is that include pages are processed before the ASP page is processed. This means that the ASP interpreter is handed an ASP with ALL the include files on it, meaning that it has more work to do which leads to more overhead

    Beside from the advantage of Server.Execute not doing this, it also allows you to dynamically build up the name of the page you want to include, making it more flexible

  6. #6
    SitePoint Member interpeo's Avatar
    Join Date
    Dec 2004
    Location
    Italy
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you don't have to process particular operations via .asp file, you can simply use #include directive!

    For example:

    ...
    <body>
    <%
    Response.Write("code of the page<br>")
    Server.Execute("exec.asp") 'transfers execution to exec.asp file
    Response.Write("returning to the code of the page<br>")
    %>
    </body>
    </html>

    #include directive should be sufficent, otherwise Server.Execute is the right choose.

  7. #7
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    However, I would suggest the Server.Execute even if you don't have any ASP on the include pages. Breaking out the <% %> tags is terribly inefficient and can add a surprising amount of overhead!


  8. #8
    SitePoint Member interpeo's Avatar
    Join Date
    Dec 2004
    Location
    Italy
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It depends on needs, anyway you dhtmlgod is right!

  9. #9
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    Watford, UK
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hhhmmmmm, I see where your going but i'm not sure it's what i'm after. Basically I will create a template page with all the graphics, then clicking on a link will pull in a flat html file (this file will only include text). Maybe the code above is correct, if so can you show me how to pull different text into the page using a link (sorry - new to ASP, my server does not support it!).

    I'm trying to create something similar to:

    index.php?page=contact
    index.php?page=services

    etc
    etc

  10. #10
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For the index.php?page=contact, thats the name of the page you would pull through?

  11. #11
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    Watford, UK
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, the page would be content.html and it would be hidden in a folder somewhere, the content.html page will only be text


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •