Problems with include in an if statement - preCharge Forums
It shows that you are unregistered. Please register with us by clicking Here
preCharge Forums


Nav Green LeftNav Right
preCharge Forums > Website Design & Development > Programming > ASP » Problems with include in an if statement


Reply
Tcat Right
 
LinkBack Thread Tools Display Modes Tcat Right
Old 07-27-2006   #1 (permalink)
cameron
Junior Member
 
Join Date: Jul 2006
Age: 40
Posts: 27
Default Problems with include in an if statement

Hey all,

We're having some trouble here that 4 web developers haven't been able to solve. Hopefully a few more minds will be able to.

Here are the players:
A classic ASP page
A database call
and An include file

Here's the problem.

If we call the include file (using any method -- we've tried <% %>, response.writefile, response.write, server.execute...), it operates just fine.

However, the second we put that include file into an if/then statement based on the results of the database query, it breaks. The static HTML code will parse, but none of the ASP *or* Javascript *or* vbscript on the included file will parse.

What we want is for this pseudocode to operate:

run database query
If query.name = "bob" then
- include file
else
- include other file
end if

The "magic code" in the include file is nothing more than a javascript countdown (or an ASP countdown or a vbscript countdown, none work)

Any help would be greatly appreciated!!
thanks
cameron
cameron is offline   Reply With Quote


Old 08-15-2007   #2 (permalink)
bazgow
Junior Member
 
Join Date: Aug 2007
Posts: 2
Default Re: Problems with include in an if statement

I do not think you can run includes based on an IF statement, as I have been having similar problems (although my query is not based on results from a database call). I may be wrong, but is it running both includes? I think that it does the including prior to running the full page's ASP. Therefore maybe your includes are fighting with each other or something? I may be wrong though!
bazgow is offline   Reply With Quote

Old 08-15-2007   #3 (permalink)
bazgow
Junior Member
 
Join Date: Aug 2007
Posts: 2
Default Re: Problems with include in an if statement

Quick update through a bit of googling:

The ASP parser includes a file before executing any script commands. This means you can't put a variable in the filename and include files dynamically based on that variable's value. You can, however, load the include into a SUB and call the SUB only if certain criteria are met. For instance:

<% IF foo = "bar" THEN %>
<!--#include file ="include/bar.inc"-->
<% ELSE %>
<!--#include file ="include/foo.inc"-->
<% END IF %>

Will still load both include files into the ASP script, as opposed to only loading one of them. However, a cleaner way to do this might be:

<% IF foo = "bar" THEN
BAR
ELSE
FOO
END IF %>

<% SUB FOO %>
<!--#include file ="include/foo.inc"-->
<% END SUB %>

<% SUB BAR %>
<!--#include file ="include/bar.inc"-->
<% END SUB %>
bazgow is offline   Reply With Quote

Reply

« Image Upload | - »


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
What does a server-side include do? agaba175 ASP 0 08-05-2006 07:36 PM
Update statement peyton ASP 2 07-13-2006 02:32 PM
What would include in a small business tool kit cameron General Business Issues 1 07-05-2006 08:48 PM


footer left
All times are GMT. The time now is 02:41 AM.

DISCLAIMER: preCharge Risk Management is not responsible for any opinions, advice or comments expressed on the preCharge Community Forums.
preCharge® is a registered trademark of preCharge Risk Management | chargeback protection | Merchant Account Blog

Powered by vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC6

Advertising | Free photo hosting | Loans | Credit Cards UK | Mortgage

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49