Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 28th, 2004, 01:17 PM
Registered User
 
Join Date: Mar 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Gravicapa
Default How to use "#include file in if..then statment?

I want to put "#include file " in <td> tag depends on if ..then statment.
How can I do that. Maybe I have to do different way?


 
Old March 28th, 2004, 02:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have heard - and therefore may be wrong - that all include statements are processed as the first thing done; i.e. include statements cannot be used the way you say unless you do some hacking like doing a redirect if some condition is fullfilled and then include the right file etc.

Hope it helps!

Jacob.
 
Old March 29th, 2004, 03:50 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Jacob is right. If you are using IIS5+ you can use Server.Execute instead of the #include.
 
Old March 29th, 2004, 04:18 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

All include statements are processed and thus the files are included before the page is processed, but the included pages are not actually processed. Essentially, the ASP runtime takes all the files that are in the requested page (the main .asp file and any #included ones) and constructs one long page of code. It then processes the whole thing. Assuming that the code that is in one include file can safely live between an If and Else/EndIf it is perfectly allowable. Just remember that the file will always be included whether or not it's processed.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old April 15th, 2004, 03:18 PM
Registered User
 
Join Date: Apr 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to pherms Send a message via Yahoo to pherms
Default

I don't agree with that.

Yeterday I've build an asp app with a lot of if...then statements.
each if..then statement checks if some variables are true. If so, then file is loaded.

Here is an example:

<%
if bla="blabla" then
%>

<%
end if
%>
 
Old April 15th, 2004, 03:34 PM
Authorized User
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hcweb
Default

I had this very same problem awhile back and Imar was nice enough to send these links. You can view this topic on this very board at http://p2p.wrox.com/topic.asp?TOPIC_ID=5960 or page 19.

I could include htm/html files no problem, but the minute I tried to dynamically include an ssi that executed code, it would crash. The 2nd link from above is from 4GuysFromRolla, and that article solved my problem.
 
Old April 15th, 2004, 04:39 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Pherms,

Planoie, pgtips and jacob are all right, in what they say. It is not possible to implement include files that way. It wont work as expected.

Even if your "If ....." statement failed, still that file would be included. So did you try doing the same with multiple if meaningful conditions? That would not work as you expected.

Still it is possible to do so. Read this article. You would get this solved.

http://www.4guysfromrolla.com/webtech/022504-1.shtml

Cheers!

-Vijay G
 
Old April 16th, 2004, 10:53 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Quote:
quote:Originally posted by pherms
Here is an example:
<%
if bla="blabla" then
%>

<%
end if
%>
Perhaps the reason you think that works is because you are missing the ever critical # that makes the comment into an include directive.

To prove that all files are always included, try this:
<% If False Then %>

<% End If %>

When I run this, I get this error despite a condition that ensures that the include file will never be processed:

Error Type:
Active Server Pages, ASP 0126 (0x80004005)
The include file 'nonExistantFile.html' was not found.
/test/asp/conditionalIncludes.asp, line 10

Peter
-------------------------
Work smarter, not harder





Similar Threads
Thread Thread Starter Forum Replies Last Post
Include file morpheus BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 April 23rd, 2006 08:20 AM
difference between include file & include virtual crmpicco Classic ASP Basics 2 January 23rd, 2006 11:50 AM
Include File morpheus Beginning PHP 8 January 17th, 2006 09:30 AM
Include file within aspx jieli1001 ASP.NET 1.0 and 1.1 Professional 2 July 29th, 2003 04:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.