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
Variable inside of an include - How to accomplish?
Old 02-03-2006, 12:33 PM Variable inside of an include - How to accomplish?
ChipJohns's Avatar
I don't know! Do you?

Posts: 488
Name: Chip Johns
Location: Savannah Georgia
Trades: 0
Hi again guys, I have a situation I can't figure out!

I have a page that is going to pull records from an
ms access database. The records are going to display
items that are for sale for an event rentals company,
used equipment they are selling off. They can input
the items into the database, however, the limit of
250 characters is not adequate for the next thing
that I want to accomplish.

There is going to be a link for each item that is going
to open a pop up window with more info about the item.
I want to enable my client to put a page (for each item)
in a folder that will hold this info. I want to name the file
for each item with the item's Stock Number (ex: 4556.inc)
and then pull this file into the pop up file. (Hope this
explanation makes sense.)

This way the file name for the include inside the pop up
window can be dynamically generated. Everything is fine,
except, I can't get the include to work.

Here is what I am doing..

<!--#include file=<%= objRS("StockNo") %>.inc-->

I wrap this in <p> tags and there you have it.

I am getting this error message with this:
  • Error Type:
    Active Server Pages, ASP 0126 (0x80004005)
    The include file '<%=' was not found.
    /newsite/used/notespage.asp, line 39
notespage.asp is the pop up page that should load the .inc file inside of it.

Any opinions, direction, is appreciated..


Thanks
ChipJohns is offline
Reply With Quote
View Public Profile Visit ChipJohns's homepage!
 
 
Register now for full access!
Old 02-03-2006, 07:02 PM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It won't work, you cannot dynamically include files.
so I use the FSO to stream the HTML code directly
Code:
<%StreamText("path_&_filename")%>
And the sub code is
Code:
Sub StreamText(TextFileName)
' read in a file and stream it out to the browser
Dim objFSO, objTextFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(Server.MapPath(TextFileName))

Do While Not objTextFile.AtEndOfStream
	Response.Write objTextFile.ReadLine  & vbCrLf 
Loop
objTextFile.Close
Set objTextFile = Nothing
Set objFSO = Nothing
End Sub
The only limitation is you cannot have executable ASP code in the include file.

The 254 character limitation is only for text fields, it you use a memo field the number of characters is limited to 64K, that should be enough
__________________
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 02-04-2006, 11:26 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
Just as an add on to that, the reason you can't do anything jazzy with ASP and Include files is that IIS processes #include directives before the ASP code. It's the same reson you can't (or shouldn't) do things like:
Code:
if x = 1 then
    <!--#include file="myfile1.asp"-->
else
   <!--#include file="myfile2.asp"-->
endif
The above works, in some cases (i.e. if there are no common varible names within the 2 files) but it's usually very bad coding practise to do it like that. Specially if the ASP files are quite big...
__________________
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 02-05-2006, 12:34 AM Re: Variable inside of an include - How to accomplish?
ChipJohns's Avatar
I don't know! Do you?

Posts: 488
Name: Chip Johns
Location: Savannah Georgia
Trades: 0
Cris and Minaki

Thanks, I will try this. (And, I'm sure it will work.)

So am I right in assuming that the include code is not asp but rather is a function of iis..?

If I run the <!--#include file="myfile.htm"--> in a straight htm file on an NT server with iis it will work..?

Thanks, Guys (& Girls)

Chip
ChipJohns is offline
Reply With Quote
View Public Profile Visit ChipJohns's homepage!
 
Old 02-05-2006, 04:28 AM Re: Variable inside of an include - How to accomplish?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
The code is a SSI (Server Side Include) directive so would only work when used on .shtm or .shtml pages under default settings. The ASP interpreter includes the SSI functions so it works on .asp pages also.

You can change the way file extensions that will be handled by IIS by changing the Application Mappings.

Conditional includes (as in Minaki's example) can be done, but as pointed out you should ensure that all common variables are declared in the parent page before the condition occurs, and they should be destroyed when finished with. That way the included page sizes do not have any major effect on server CPU load or page load times as only the code in the condition that is met will executed. It will however have some effect on server memory resources because the code from all the included files will be buffered.

It is also good practice to use <%option explicit%> and DIM all variables in the page as this cuts down on the processing needed. It's good practice anyway but a little more important in this scenario.
__________________
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 02-06-2006, 12:13 AM Re: Variable inside of an include - How to accomplish?
ChipJohns's Avatar
I don't know! Do you?

Posts: 488
Name: Chip Johns
Location: Savannah Georgia
Trades: 0
Thanks for the explanation Cris. It is much appreciated...
ChipJohns is offline
Reply With Quote
View Public Profile Visit ChipJohns's homepage!
 
Reply     « Reply to Variable inside of an include - How to accomplish?
 

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