By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,310 Members | 1,430 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,310 IT Pros & Developers. It's quick & easy.

Dynamic Includes in ASP

P: 46
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
Share this Question
Share on Google+
1 Reply


jhardman
Expert 2.5K+
P: 3,405
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

Post your reply

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