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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternative for Server side include

Status
Not open for further replies.

Faheemi

Programmer
Sep 2, 2001
59
HK
Hello,

I want to include an ASP file into another ASP file without using the server side include. The reason why I am finding an alternative for the server side include is explained as follows:

file1.asp
*********
<%
If a > 10 Then
%>
<!--#include file=&quot;inc1.asp&quot;-->
<%
Else
%>
<!--#include file=&quot;inc2.asp&quot;-->
<%
End If
%>

inc1.asp
********
Dim x
x=10
Respose.Write (x)

inc2.asp
********
Dim x
x=20
Respose.Write (x)


When I run file1.asp it I get the following error:

Microsoft VBScript compilation (0x800A0411)
Name redefined

I know this happens since the variable x is DIM'med 2 times. Even though I include the inc1.asp and inc2.asp conditionally, they both are included prior to the ASP compilation (and the variable x get Dim'med twice). This is an ugly part of the server side include.

That's why I am trying to find a way to get around this problem.

Any helps will be greatly appreciated.

Thanks and regards,

Faheem Hameed


 
I think you are slightly mixed up on how includes work, they will be included on the page regardless of if its in an if else or some other conditional statement.

What you can do is put the include tags near the top of the page (after the <%@language ....) and then put your include asp coded inside a sub or function and then call that sub or function from within your conditional statement
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top