Include dynamically with ASP

Results 1 to 4 of 4

Thread: Include dynamically with ASP

  1. #1
    Join Date
    Dec 1969
    Posts
    1,156

    Default Include dynamically with ASP

    Is there any way of dynamically including content based on the string submitted from another page to another? I would ideally like to do the following: <BR>In one page: &#060;a href="index.asp?content=computer">goto my computersite&#060;/a><BR><BR>In index.asp: <BR>&#060;!--#include file=" &#060;% Request("content") &#037;&#062; " --><BR>I know the fact that the include is parsed before the asp code but is there anyway to bypass this? Is there maybe a component for this?<BR><BR>James

  2. #2
    e Guest

    Default RE: Include dynamically with ASP

    This should work (hypothetically):<BR><BR>&#060;%<BR><BR>File = Request.QueryString("content")<BR><BR>IncludeFile = Server.MapPath(File)<BR><BR>Set fs=Server.CreateObject("Scripting.FileSystemObject ")<BR><BR>IF fs.FileExists(IncludeFile) Then<BR><BR>Set f = fs.openTextFile(IncludeFile)<BR><BR>varContent = f.readall<BR><BR>Set f = nothing <BR><BR>Set fs = nothing <BR><BR>Response.Write(varContent)<BR><BR>End if<BR><BR>&#037;&#062;<BR><BR><BR>This is mainly to get you on the right track, but I know it can be done.

  3. #3
    Join Date
    Dec 1969
    Posts
    1,156

    Default RE: Include dynamically with ASP

    Thanks for your answer, but if I do it the way you suggested the included asp-code isn&#039t parsed at all. I want to include and asp-page with code so the asppage must be parsed when included.<BR><BR>Thanks, James

  4. #4
    Stephen Fisher Guest

    Default RE: Include dynamically with ASP

    I just tried to do this yesterday and as I expected, it didn&#039t work.<BR><BR>Something that will is, use the FileScriptingObject to write a file that includes the include you want as well as an include for the page that is supposed to have the first include. Then do a response.rediredt to the new page.<BR><BR>The file that gets written is xxxxx.asp and is<BR>&#060;!--#include virtual="theonetoinclude.asp"--><BR>&#060;!--#include virtual="theoriginal.asp"--><BR><BR>This will work. You can use a random number for the file that gets generated or use the session.sessionID (unique) for the filename and then dynamically do the response.redirect


Posting Permissions

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