Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Include Pages - an alternative function

ASP 101

Dynamic Include Pages - an alternative function

by  walderr  Posted    (Edited  )
After thinking it was impossible to include .asp pages dynamically, I've managed to crack a way of doing it, which although technically not an 'include' method, uses the Server.Execute function to get round the problem as follows:

On the main page you wish to view, use the function
Server.Execute "Folder/"&Variable&".asp"
where you want it to appear - this will 'include' the relevant file.

On the page you are including, if you wish to execute asp within it, you can use the following method under some circumstances:
Make sure that the variable is taken to the main page in a query string, ie the address off the main page will be in the format mainpage.asp?my_var=<%=my_var%>

On the included page, use
QueryString = Request.ServerVariables("QUERY_STRING")
This takes the variables from the url of the main page (eg my_var=<%=my_var%> in the above example). You can then chop this up so that the particular variable you want is taken for use in the include page (eg my_var).

In short:

MAIN-------------------------------
mainpage.asp?my_var=<%=my_var%>
Server.Execute "Folder/"&Variable&".asp"

INCLUDE----------------------------
QueryString = Request.ServerVariables("QUERY_STRING")
Cut = split(QueryString,"=")
Paste = ubound(Cut) - lbound(Cut) + 1
my_var = (Cut(Paste-1))

And there you have it. The variable can now do its job on the included asp page, which sits inside the main asp page. Very simple, but it worked for me!
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top