Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<!-- #include file=... Name redefined...

Status
Not open for further replies.

nphani

Technical User
Feb 10, 2002
104
US
This must be a very simple question for most of you, but is important to me becos of the time constraint...

I have a file say incFile.asp which declares variable as:
Dim strConnection

I include this asp in every file that needs a database connection (I should have used Application variable, but it was built that way earlier and is very tough to change completely...)

I have a file, say parentFile.asp that calls another file, say childFile.asp and also includes the above asp:

<!--#include file=&quot;incFile.asp&quot;-->
myVar = &quot;true&quot; <--------- setting a variable to distinguish b/w parent and child
<!--#include file=&quot;childFile.asp&quot;-->

in childFile.asp too, I need incFile.asp. So, in childFile, I should not include incFile when parent is including child. Else, I should include incFile in childFile. For this, I am trying to use some variable called myVar (shown above). In childFile, I check this variable and if it is not true, I include incFile.

This doesnot seem to work as anytime, the error comes up saying:
Name redefined
Dim strConnection

Whats wrong and Is there any other way to do it?

Thanx
 
You shouldn't decalare the same variant name in included files.

Remember that ASP doesn't do the include, but IIS does. When ASP looks at your page, it looks at it as one big script instead of two scripts because IIS merged them together when you used the <!--#include--> directive.

You might be able to get around this by using the Server.Execute(&quot;childFile.asp&quot;) command.
 
Great baddos,
That works fine.. but for one thing thou..
I want to send a variable to the childFile, saying if you are being server.executed, then finally redirect to one page, else go to other. I am trying to use query strings, but they don't seem to work. any other way out?

Phani
 
The diference with inlcude is that the code is all the time there but you cant or can execute it.

So if you gonna say something like this

if myVar=&quot;true&quot; then
<!--#include file=&quot;incFile.asp&quot;-->
end if

The code is included but executed only if myVar=&quot;true&quot;.

Would looks same as this
if myVar=&quot;true&quot; then
'paste the code of the incFile.asp here
end if

As i see from you it seems that you want to include a file in itself, it's not posible.

________
George, M
 
I finally sorta cleared the problem...
I am now using a callChildFile.asp which includes the incFile.asp and childFile.asp. So any file that wants to use ChildFile.asp (and doesnot contain incFile in it) will use callChildFile.asp. Files like parentFile.asp (which have incFile included) will directly include childFile.asp

This is solving the current issue and everything is working fine for me.. thou not sure if this is the best way to get around.

Thanx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top