home

Tutorial: ASP #include for content

A rather useful thing to use in asp is the 'include' function. This allows a file to be included in a web page when the browser renders that page. Asp files can be included in asp pages , as can .txt files, and many other formats.

Like the php version, the asp include can be a powerful & useful addition to a web designer or developer's skillset. Having the flexibility to create a page section once and then include it inside other pages at will goes a long way toward site control & overall continuity, both of design & user experience.

Including the file:


Once the asp file and the file to be include are created, place the following code in the asp file (in the Code View if you're using Dreamweaver®). Modify the path & file name to point to the included file.

<!--#include file ="path/included_file.extension"-->

Dreamweaver®'s internal preview will also show the included file in the page, provided it does not require a server to process it (a .txt file, for example). Included asp files wil get an asp icon.

Example 1:


This paragraph comes from a separate text file. Pretty cool. One of the possible uses: a client could update this file, without inadvertently destroying the actual page. One downside: in the text file, each sentence is on it's own line. As you can tell, when it displays here that formatting goes away.

OK, so formatting in a text (.txt) file does not carry through into a web page. So, then it might make sense to use a Rich Text File (.rtf) since that file type carries formatting with it. The following paragraph comes from such a file.

Example 2:


{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf330 {\fonttbl\f0\fswiss\fcharset77 Helvetica;} {\colortbl;\red255\green255\blue255;} \margl1440\margr1440\vieww9000\viewh8400\viewkind0 \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural \f0\fs24 \cf0 This content comes from a separate text file.\ Pretty cool.\ One of the possible uses: a client could update this file, without inadvertently destroying the actual page.\ One downside: in the text file, each sentence is on it's own line. As you can tell, when it displays here that formatting goes away.}

Well, that didn't work so well. Once is while a client will ask about using a Word® file. As a last-ditch attempt, we could try that. Initially I included a .doc file below this paragraph. Turns out that it blew up this page so bad that it just wasn't worth showing.

Errors:


When this type of thing blows up, the message below is what the user gets to see. No page, no content, just the message below.

Active Server Pages error 'ASP 0126'

Include file not found

/path/path/main_file.asp, line 48

The include file 'path/included_filename.extension' was not found.

Resources:


A good place to follow up on this idea is w3schools. Other good resources include ASPfree, Aspin, & CodeFixer.