Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP Include problem

Posted on 2006-06-29
3
Medium Priority
?
693 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
[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
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

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

Question has a verified solution.

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

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

715 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