Forum Moderators: open

Message Too Old, No Replies

ASP Include : use if then statement

to include an asp page.

         

irishaff

6:01 pm on Dec 20, 2004 (gmt 0)

10+ Year Member



Hi,

I am happy that i can write the conditional stuff, what im not sure about is if the " condition " turns out to be true can i say " then " include xyz.asp . I have scouted around google for help but cant find any .

Any advice would be great.

txbakers

6:09 pm on Dec 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<% if cond1 = true then %>
<!-- #include file="file1.asp" -->
<% elseif cond2 = true then %>
<!-- #include file="file2.asp" -->
<% end if %>

something like that should work.

Also do a search in this forum, it's come up before.

john_k

6:10 pm on Dec 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No. The includes are performed before the script is executed.

The best alternative with classic ASP is to utilize Server.Execute. So you can do something like this:


Select Case lSomething
Case 1
Server.Execute "something-1.asp"
Case 2
Server.Execute "something-2.asp"
Case 3
Server.Execute "something-3.asp"
Case Else
Server.Execute "something-x.asp"
End Select

The script that gets executed would then put results into the Session object which you could then read from your main script and/or they can use Response.Write statements to send output.

john_k

6:13 pm on Dec 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Although what tx posted might work, it would result in BOTH file1.asp and file2.asp being included. So, besides the inefficiency of loading all possible files, you run the risk of duplicate name definitions. That is, if file1.asp and file2.asp both declare the same variable, you will get a server-side scripting error.

irishaff

6:14 pm on Dec 20, 2004 (gmt 0)

10+ Year Member



thank you for such a fast answer guys. This has been most helpful and allows me to furhter my site no end.

Thanks

David

irishaff

11:23 am on Dec 23, 2004 (gmt 0)

10+ Year Member



Just to follow up. It transpired that a server.response statement worked best as it allowed me to put an else if statement in and not have to cover every possible option.