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
- <%If (Session(“accounttype”)=1)% Then>
- <!--#include file="footer1.asp" -->
- <%Else%>
- <!--#include file="footer1.asp" -->
- <%End If %>
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
- <% Dim selectInclude
- selectInclude = Session("sccounttype")
- Select Case selectInclude
- Case "99" %>
- <!-- #include file="footer1.asp" -->
- <%Case "2"%>
- <!-- #include file="footer2.asp" -->
- <%Case "3"%>
- <!-- #include file="footer2.asp" -->
- <%End Select%>
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
- <% Dim selectInclude
- If Session("AccountType") = 1 Then
- selectInclude = 1
- Else
- selectInclude = 2
- End If
- Select Case selectInclude
- Case "1" %>
- <!-- #include file="footer1.asp" -->
- <%Case "2"%>
- <!-- #include file="footer2.asp" -->
- <%End Select%>
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