Solved

ASP Include problem

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to count occurrences of each item in an array.

628 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