SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2002
    Location
    Newcastle, UK
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using if/else to decide on an include file?

    Hi there,

    Is it possible to code the correct file name of the include file on my document, using the if/else statement? The filename will be dependant upon a variable being passed through into this document called PageID,

    i.e. if pageID = 4, then filename = includefile4.asp

    What is the correct syntax for this? Go easy on me, I'm new to ASP!

    Thanks,

    Entropy

  2. #2
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just covered this last week in another post.. but I'll go over it again.

    Server-side includes (<!--#include file=""-->) are processed before the page is sent thru the ASP interperter. Mean that you can me around with it with ASP.

    To counter this, there us an Execute method of the Server object, which transfers Execution to another page. So using it with your example:

    [vbs]
    If ( pageID = 4 ) then
    filename = includefile4.asp
    End If

    Server.Execute(fileName)
    [/vbs]

    Hope that helps


  3. #3
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Originally posted by dhtmlgod
    I just covered this last week in another post.. but I'll go over it again.

    Server-side includes (<!--#include file=""-->) are processed before the page is sent thru the ASP interperter. Mean that you can me around with it with ASP.

    To counter this, there us an Execute method of the Server object, which transfers Execution to another page. So using it with your example:

    [vbs]
    If ( pageID = 4 ) then
    filename = includefile4.asp
    End If

    Server.Execute(fileName)
    [/vbs]

    Hope that helps

    Remember, Server.Execute() is IIS 5.0+ (Win2000 and XP) only, meaning if you are on an NT server you are SOL. Trust me, I work with NT4's limitations every day.

    --Vinnie

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2002
    Location
    Newcastle, UK
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Guys,

    Many thanks for your help - sadly as it is I'm using NT4 so thanks also for that advice Vinnie.

    Cheers,

    Entropy

  5. #5
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Originally posted by entropy
    Hey Guys,

    Many thanks for your help - sadly as it is I'm using NT4 so thanks also for that advice Vinnie.

    Cheers,

    Entropy
    Another way you can do this, albeit much less elegant than Server.Execute() would be to put your code in if/else blocks rather than include files. See example below:
    [vbs]
    <%if variable = 1 then%>
    ...#1's code here
    <%elseif variable = 2 then%>
    ...#2's code here
    <%end if%>
    [/vbs]

    Or you can place HTML/JavaScript code in separate files and use the FileSystemObject or ADODB.Stream to get its contents. You can't have any ASP code in this type of solution however, and the first way is better suited to running ASP code once the block is called.

    --Vinnie


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •