473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Dynamic Includes in ASP

Hi Everyone,

I have newly started as a ASP developer. I have been working on some change request and was blogged down with dynamic includes. Eventually I had managed to figure out the problem and find a solution. I am posting my findings for two purpose:

1) Help someone else who faces the same problem
2) Experts to point me to a better solution to the same porblem.


Problem: The are three different types of user to a system: Admin1, Admin2 and Admin3. All the three user are doing the same admin functionality - Add New user to the system but the admin add new user form should show different footers - footer1 for Admin1 and footer2 for admin2 and 3.

The admin type is determined by accounttype which is a session varible, so I tired the obvious solution

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%If (Session(“accounttype”)=1)% Then>
  3. <!--#include file="footer1.asp" -->
  4. <%Else%>
  5. <!--#include file="footer1.asp" -->
  6. <%End If %>
  7.  
  8.  
The page kept throwing the followign error -
Microsoft VBScript runtime error '800a01f4'
Variable is undefined: 'SQLAccess'
footer1.asp, line 74

I tired, the same code with Response.Write and it was working fine. A simple google pointed me to an article explaining about Server Side Include and hence for the same reason I was not able to use the aboce code.

The actual Solution to the problem was thought to be:

Expand|Select|Wrap|Line Numbers
  1. <% Dim selectInclude
  2. selectInclude = Session("sccounttype")
  3.  
  4. Select Case selectInclude 
  5.  
  6. Case "99" %>
  7. <!-- #include file="footer1.asp" -->
  8.  
  9. <%Case "2"%>
  10. <!-- #include file="footer2.asp" --> 
  11.  
  12. <%Case "3"%>
  13. <!-- #include file="footer2.asp" --> 
  14.  
  15. <%End Select%>
  16.  
but again I got error -
Active Server Pages error 'ASP 0126'
Include file not found
createUser.asp, line 669
The include file 'footer2.asp' was not found.

I had no clue why it showed me this error as I was quite sure for the code to work but a little trying around - I figured the EXACT working code is:

Expand|Select|Wrap|Line Numbers
  1. <% Dim selectInclude
  2.  
  3. If Session("AccountType") = 1 Then 
  4. selectInclude = 1
  5. Else 
  6. selectInclude = 2
  7. End If
  8.  
  9. Select Case selectInclude 
  10.  
  11. Case "1" %>
  12. <!-- #include file="footer1.asp" -->
  13.  
  14. <%Case "2"%>
  15. <!-- #include file="footer2.asp" --> 
  16.  
  17. <%End Select%>
  18.  
  19.  
Questions from experts:
1) Though I have vague idea about why my second piece of code didn't work, I would request a clearer reasoning.
2) Is there any other better way of doing it?

Hope any looking for dynamic include finds it useful and I get more clearer about this concept.

Thanks and wishes
Sree
Jun 11 '07 #1
1 1558
jhardman
3,406 Expert 2GB
Sree,

First code should work fine besides that the % is in the wrong place:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. If Session(“accounttype”)=1 Then %>
  3.    <!--#include file="footer1.asp" -->
  4. <%
  5. Else %>
  6.    <!--#include file="footer2.asp" -->
  7. <%
  8. End If %>
  9.  
The error code you showed does not appear to be related to this problem.

One thing that I have seen that causes the logic to fail in these cases is when the variable is supposed to be an integer but is actually a numeric string. In other words you need to distinguish between
Expand|Select|Wrap|Line Numbers
  1. session("accounttype")=1
and
Expand|Select|Wrap|Line Numbers
  1. session("accounttype")="1"
Does this make sense?

Jared
Jun 11 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: jason | last post by:
Will this work - dynamic determination of root (local or web host) and consume this in include file anywhere. I am concerned about dynamic construction of virtual absolute include in the consuming...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
1
by: Satish.Talyan | last post by:
hi, i want to create a dynamic tree hierarchy in javascript.there are two parts in tree, group & user.when we click on group then users come under that's tree category will be opened.problem is...
7
by: Ajinkya | last post by:
I have writen a program for a game called game.exe Now it includes a player part to which has to be a function to be writen by someone else. Now I want to provide this exe to some tester who...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.