Solved

ASP Include problem

Posted on 2006-06-29
3
686 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 500 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
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 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…

816 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

7 Experts available now in Live!

Get 1:1 Help Now