Solved

ASP Include problem

Posted on 2006-06-29
3
684 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
Comment Utility
try making it b.asp a b.inc file instead

also, whats the error
0
 
LVL 1

Expert Comment

by:alexionel
Comment Utility
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 500 total points
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now