![]() |
|
|
Dynamic IncludesThe most important thing to note is that server side include files are inserted into their holding file before any of the holding file is processed. The include file is parsed before any ASP code so you can't use ASP variables in server side includes like the example 1 below. In example 1 below the variable 'whichpage' will not exist at the time the include file is parsed. Example 1: <% The code in example 1 is trying to dynamically generate the name of the include file. We were trying to send a string through the querystring and assign it to the variable 'whichpage' and then it was our intention that that variable would go with the .asp file extension and make up an asp file name. Unfortunately, since the web server first inserts the include file, it will attempt to include a file with the name <%= whichpage %>.asp . This will generate an error as that file does't exist. The way I would suggest that we go about dynamic includes is to include all files and use some conditional statement to make sure that only one will actually be executed. The following code should work: Example 2: <% The above code will include all three include files but depending on the value of our variable 'whichpage' only one file makes up the outputed page.
Site developed by Michael Wall - Web Design Belfast N.Ireland. |
|