?
Solved

Does ASP have a require function, similar to the require function in PHP?

Posted on 2003-03-07
4
Medium Priority
?
299 Views
Last Modified: 2012-06-27
In PHP, you can use the require function. It is similar to the include directive in C or the require directive in Perl.  In PHP, when the require function is processed, it is replaced with the file that it points to.  This is a good way to separate HTML from PHP and to reuse code.  For example:

<?
include("claFunc.inc");
require("tag-head.html");
require("tag-styles.html");
require("tag-head-end.html");
require("tag-body.html");

// here is where the body of this particular page would be built...
// could be just print statements of html, function calls, etc...

require ("tag-endpage.html");
?>

The require functions above open the html files they point to.  The contents of those files, in this case, pure html, will become part of the resulting page...  

I want to accomplish something similar in ASP.  Maybe ASP has a similar function and I'm just missing it, as i am still somewhat new to ASP...

<%
#include file="somefile.inc"
require file="tag-head.html"
require file="tag-styles.html"

// body of page goes here....

require file="tag-endpage.html"
%>

Thanks in advance!

Preece
0
Comment
Question by:Preece
[X]
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
4 Comments
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8090677
what you can do is create an INCLUDE file (thefile.inc) in which you set your script delimiters and input your code:

TheIncludeFile.inc:

<%
function GetLastURL()

GetLastURL=Request.ServerVariables("HTTP_REFERER")

end function
%>

and then simply include it in your HTML document:

<html>
<head>
</head>
<body>
ASSUMING THE FILE IS IN THE SAME FOLDER:
<!-- #INCLUDE FILE="TheIncludeFile.inc" -->
ASSUMING IT IS IN A DIFFERENT FOLDER
<!-- #INCLDE VIRTUAL="Http://ServerName/SpecificFolder/SubsIfAny/TheIncludeFile.in" -->

so then you can use the function GetLastURL in your code anywhere on this page!
<%
Previous=GetLastURL()
%>

</body>
</html>

and there you have it...

Hope this helps!

MaxOvrdrv2
NOTE: you must include the file on every page!
0
 
LVL 28

Accepted Solution

by:
sybe earned 200 total points
ID: 8090679
In ASP you can use the SSI commands, like this
<!--#include file="myinclude.asp"-->

It does not matter if the included file contains ASP or HTML or both.
Note that you should use it outside of the <% and %> tags.
0
 
LVL 15

Expert Comment

by:gladxml
ID: 8092167
Preece,

Try to check out the link.. might help...

http://www.4guysfromrolla.com/webtech/faq/Intermediate/faq7.shtml
0
 
LVL 12

Author Comment

by:Preece
ID: 8163311
Thanks, this works well!
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

777 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