Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How can i dynamic-include a page(ASP or Html)?

Posted on 1999-08-02
Medium Priority
Last Modified: 2013-11-18
i wanna dynamic include a page at run-time, just like:
  if URL="" then URL="new.asp"
<!--#include file="<%=URL%>">
as you know, this code dont work.
Can you help me??
Question by:cakkme
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
LVL 33

Expert Comment

ID: 1852618
If the number of possible values for Request("url") is finite and reasonable, ( no more than 5 or 6 ), it might be easier to just include them all and put code like this in each file -- for example in new.asp:

  If URL = "new.asp" Then


  End If

Accepted Solution

davidmiles earned 200 total points
ID: 1852619
You cannot dynamically construct a #include
directive.  However, you may be able to work around this by putting the #includes in an If-Then or Select Case construct.  For example,

Select Case Var1
  Case "file1"
    <!--#include vitrual="/includes/"-->
  Case "file2"
    <!--#include virtual="/includes/"-->
End Select

This will include both and, but program flow will be controlled by the Select Case, resulting in only one file's code being executed.
LVL 10

Expert Comment

ID: 1852620
YOu can also read the contents of that file and write it to the browser... That will eliminate the need to KNOW which files you are going to include.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 1852621
but what if there is script in there to be processed that willnot be if you read the file and send the content to the browser
LVL 33

Expert Comment

ID: 1852622
even if you put the includes in a case or if-then structure, they are still ALL included.  The only difference between your suggestion and mine is that the if logic is in one place -- which might make things easier to understand from a code-maintenance perspective.


Expert Comment

ID: 1852623
yeah I realise that I was replying to the "YOu can also read the contents of that file and write it to the browser" comment

Author Comment

ID: 1852624
to MasseyM: if i read an ASP' content, the code in it cannot be run and just output to result page, someone
can "view source" and read my ASP code!!.
LVL 10

Expert Comment

ID: 1852625
That is true.  But, it is a VERY SIMPLE way to "include" a file without having to declare EACH one.  YOu never mentioned that you wanted to include ASP files that needed to be processed before they were included...

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question