Reply
ASP including files
Old 06-07-2005, 10:59 AM ASP including files
Junior Talker

Posts: 3
Hi!
I'm trying to put to life my first more complex page. In it, I want to include a file in a div of my index.asp page. The problem is, that I want to put diferent inc files depending on the link that viewer choosed.

In W3school I found this:

The following script will not work because ASP executes the #include directive before it assigns a value to the variable:
<%
fname="header.inc"
%>
<!--#include file="<%=fname%>"-->

Now I know, what can't work. But what will? What would be the best solution to the problem?
I will apriciate the answer!
Zvak
Zvak is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 06-07-2005, 01:48 PM
ExpressoDan's Avatar
Ultra Talker

Posts: 317
Name: This Space for Rent
Location: Georgia
The code you got from W3 by all acounts will work, best thing to do is learn by trial and error. Here are some more examples:

Virtual include (path relative to the site root)
<!--#include virtual="/folder/file.asp" -->

File include: (path relative to the document)
<!--#include file="file.asp" -->
ExpressoDan is offline
Reply With Quote
View Public Profile Visit ExpressoDan's homepage!
 
Old 06-07-2005, 03:53 PM
chrishirst's Avatar
Super Moderator

Posts: 13,671
Location: Blackpool. UK
ASP Includes
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-08-2005, 04:43 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Quote:
The code you got from W3 by all acounts will work
No it won't. He already explained why. Include's get included before any VBScript gets executed. Therefore, in the code above, the include will be looking for a file called "<%=fname%>" not "header.inc".
The reason it works this way is because one of the main uses of includes is to include files which contain functions shared by multiple ASP Pages.

Instead of using includes, provided the file you're including only contains static HTML and no ASP, you can write some code to read the contents of the file with ASP and write it back with Response.Write()
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 06-08-2005, 05:05 AM
chrishirst's Avatar
Super Moderator

Posts: 13,671
Location: Blackpool. UK
you can use conditionals. "if then " or "select case"

Code:
      <%
if CatID = 0 or isnull(CatID) then
%>
      <!--#include virtual="/include/page/inc_page_product_display.asp"-->
      <%
else
	if bUsePaging then  
%>
      <!--#include virtual="/include/page/inc_page_product_display_tn-paging.asp"-->
<%
	else
%>
      <!--#include virtual="/include/page/inc_page_product_display_tn.asp"-->
<%
	end if		  
end if
%>
Code:
<%
select case action
case "logon" 
%>
<!--#include virtual="/include/page/inc_page_logon.asp"-->
<%
case "reset" 
%>
<!--#include virtual="/include/page/inc_page_logon.asp"-->
<%
case "edit" 
%>
<!--#include virtual="/include/page/inc_page_edit.asp"-->
<%
case "update" 
%>
<!--#include virtual="/include/page/inc_page_updated.asp"-->
<%
case "new" 
%>
<!--#include virtual="/include/page/inc_page_added.asp"-->
<%
case "approve" 
%>
<!--#include virtual="/include/page/inc_page_confirm.asp"-->
<%
case "remove" 
%>
<!--#include virtual="/include/page/inc_page_leaving.asp"-->
<%
case else
%>
<!--#include virtual="/include/page/inc_page_register.asp"-->
<%
end select
%>
However all the includes will be parsed and included in the main file but only the one will be actioned.
Just be aware of variable names and scoping in the included files. use option explicit and ensure that anything common is declared in the parent page.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-08-2005, 08:50 AM
ExpressoDan's Avatar
Ultra Talker

Posts: 317
Name: This Space for Rent
Location: Georgia
My sincerest apologize, it looked like a great idea to me but had never actually done that. I don’t mean to give false information, thank you for correcting me

D
ExpressoDan is offline
Reply With Quote
View Public Profile Visit ExpressoDan's homepage!
 
Old 06-14-2005, 06:08 AM
Junior Talker

Posts: 3
Thanks all of you. At the end I managed to find the solution by myself. I tried to do it with conditionals and it works... just like chrishirst sugested. The response.write solution seems like a good idea. I will try that next time.
Thanks anyway,
Zvak
Zvak is offline
Reply With Quote
View Public Profile
 
Old 06-21-2005, 06:09 PM
kline11's Avatar
King Spam Talker

Posts: 1,289
Name: John
Location: USA
So I guess a version using If Then statments won't be needed.
kline11 is offline
Reply With Quote
View Public Profile Visit kline11's homepage!
 
Reply     « Reply to ASP including files
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.20050 seconds with 12 queries