Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP Include problem

Posted on 2006-06-29
3
Medium Priority
?
697 Views
Last Modified: 2013-11-18
Hi,

I am planning to move all my DB related code into a separate file. So i have two files a.asp and b.asp.

a.asp has all the calls to b.asp.

I have all the common code in b.asp.

a.asp
<%@language=vbscript%>
<!--#include file="b.asp"-->
<%
 call hai()
%>

b.asp
<%@language=vbscript%>
<%
 sub hai()
  response.write ("hai")
 end sub
%>

but it throws error in a.asp when i try to call hai(). Let me know what i am doing wrong?

Regards, G
0
Comment
Question by:gcmachel
3 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17007999
try making it b.asp a b.inc file instead

also, whats the error
0
 
LVL 1

Expert Comment

by:alexionel
ID: 17008043
just remove from b file this code <%@language=vbscript%> and when u execute the a page be sure u executed from server not by just click on the page in explorer.  The <!--#include file="b.asp"--> tag is executed on the server. When u execute it from explorer it doesn't run the code.
0
 
LVL 16

Accepted Solution

by:
OliWarner earned 2000 total points
ID: 17013224
The extension will not be the problem.

#include is a preprocessor directive. Everything that happens in preprocessing, executes before any VBScript is run. Therefore if you include something which has a line that is required to *only* feature at the top and nowhere else, it'll throw fatal errors like it is.

So, if you need to call the b.asp page on its own, elsewhere, or you include it on every page, you'll need something like this:

a.asp
<!--#include file="b.asp"-->
<%
 call hai()
%>

b.asp
<%@language=vbscript%>
<%
 sub hai()
  response.write ("hai")
 end sub
%>


If your b only containins header functions for one or two pages, you might want to go with something like this:

a.asp
<%@language=vbscript%>
<!--#include file="b.asp"-->
<%
 call hai()
%>

b.asp
<%
 sub hai()
  response.write ("hai")
 end sub
%>

For the second method you might want to name the include file something other than .asp to stop people calling it on its own... .inc is a suitable extension.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

877 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