Lisa
Lisa

Reputation: 29

Conditional includes in ASP

We have a number of categories with products in an ASP eCommerce site and, based on the category, would like a particular file to be included. For example, if URL is:

viewPrd.asp?idproduct=6&idcategory=18

then based on idCategory=18 I would like to include:

<!--#include file="menu18.asp"-->

If idCategory=19 then I would like to include:

<!--#include file="menu19.asp"-->

and so on. Any assistance would be appreciated.

Upvotes: 2

Views: 5547

Answers (4)

acattani123
acattani123

Reputation: 39

Yes, its possible. Just leave the include statements outside the <% %> code delimiters. This is my quick and dirty solution and it works:

<% session("lang") = request.querystring("lang") %>

<%if (session("lang") = "es" or session("lang") = "") then %>
<!--#include file="espanol.asp"-->
<% else %>
<!--#include file="ingles.asp"-->
<% end if %>

<!--#include file="precios.asp"-->

IIS will include the two files, but ASP will use only the file that satisfies the if conditions.

Upvotes: 4

Niente0
Niente0

Reputation: 604

I use a script taken from https://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=9796&lngWId=4 (dynamic ASP inclusion)

So after including that script in your code, you just have to write:

myMenu = Request.Querystring("idCategory")
Include("menu"&myMenu&".asp")

Upvotes: 2

Gerson Macedo
Gerson Macedo

Reputation: 33

As far i know its not possible on a "elegant way", but i suggest you to take a look in those links:

is it possible to issue dynamic include in asp-classic?

https://support.microsoft.com/en-us/kb/192144

Regards.

Upvotes: 0

Erik Oosterwaal
Erik Oosterwaal

Reputation: 4384

Unfortunately, include files are a feature of IIS, not ASP. They are included before the page is sent to the ASP-processor that interprets your ASP code. For this reason you can't have conditional includes. The includes are already in place when the ASP code is executed.

To have conditional code in ASP you could use script components (WSC files), which you can include/load conditionally, or use big if...then or case.. constructions inside an include.

More info on the use of WSC's can be found here

Upvotes: 1

Related Questions