Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



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

Posts: 3
Trades: 0
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
 
 
Register now for full access!
Old 06-07-2005, 02:48 PM
ExpressoDan's Avatar
Ultra Talker

Posts: 317
Name: This Space for Rent
Location: Georgia
Trades: 0
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, 04:53 PM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
ASP Includes
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-08-2005, 05:43 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
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!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 06-08-2005, 06:05 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-08-2005, 09:50 AM
ExpressoDan's Avatar
Ultra Talker

Posts: 317
Name: This Space for Rent
Location: Georgia
Trades: 0
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, 07:08 AM
Junior Talker

Posts: 3
Trades: 0
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, 07:09 PM
kline11's Avatar
SearchBliss Web Tools

Latest Blog Post:
Oracle Embraces the Cloud
Posts: 1,724
Name: John
Location: USA
Trades: 0
So I guess a version using If Then statments won't be needed.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
kline11 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to ASP including files
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.80685 seconds with 12 queries