1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Is it possible to have the request as include????

Discussion in 'C#' started by ludwig, Oct 22, 2006.

  1. #1
    Hi guys,

    I am thinking to do something like in order not to use SELECT CASE

    If I pass the variable like

    ?page=home

    then in the body I should include
    SEMrush
    <!--#include file="home.asp" -->

    Can anyone tell me how to do it?
     
    ludwig, Oct 22, 2006 IP
    SEMrush
  2. YIAM

    YIAM Notable Member

    Messages:
    2,486
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #2
    You can do it by if .. else... end if

    Example:
    
    <%
    page=request.querystring("page")
    
    if page=home then
    %>
    <!--#include file="home.asp" -->
    <% end if
    if  page=contact then
    %>
    <!--#include file="contact.asp" -->
    <% end if %>
    
    Code (markup):
    Hope this will help you.
     
    YIAM, Oct 23, 2006 IP
    ludwig likes this.
  3. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #3
    I know it, it'll be beter using select case

    you may also have it like

     
    ludwig, Oct 23, 2006 IP
    YIAM likes this.
  4. 50plus

    50plus Guest

    Messages:
    235
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ludwig, you may find that your select case will not work
     
    50plus, Oct 23, 2006 IP
  5. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #5
    It has been working for 2 years for me, please clarify what you mean by that
     
    ludwig, Oct 24, 2006 IP
  6. Garve

    Garve Peon

    Messages:
    62
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    My understanding is that the INCLUDE is carried out first, and the scripting (including the scripting in the INCLUDE file) is carried out second.

    Therefore, none of the code above should work. ALL the INCLUDE files in the above code snippets would be included regardless of whether they are supposed to be or not. However, the results won't be output to HTML as the If Else statements will kick in afterwards.

    This means this isn't a particularly efficient method of doing this, and of course if the include files contain HTML outwith script delimiters then it would be output to the page, meaning that the HTML code from 1.asp and 2.asp and 3.asp etc would show up on the final page.
     
    Garve, Oct 24, 2006 IP
    50plus likes this.
  7. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #7
    do you mean that this code won't work???? but it is working pretty well you know

     
    ludwig, Oct 24, 2006 IP
  8. Garve

    Garve Peon

    Messages:
    62
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    But is it working?

    Can you be sure that all the following files are NOT being included into the page?

    <!--#include file="pricee.asp"-->
    <!--#include file="servicee.asp"-->
    <!--#include file="contacte.asp"-->
    <!--#include file="shope.asp"-->
    <!--#include file="pricer.asp"-->
    <!--#include file="servicer.asp"-->
    <!--#include file="contactr.asp"-->
    <!--#include file="shopr.asp"-->

    My suspicion is that they're ALL being included, but then when the script runs only the script within the SELECTED file is running. In that case you might as well have all your code in one page - you're not saving any resources by having the code in INCLUDE files.
     
    Garve, Oct 24, 2006 IP
  9. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #9
    Well I am not sure about that though
    But I know that it works

    thats why I am trying to find a better way for that something like include if it is needed
     
    ludwig, Oct 24, 2006 IP
  10. 50plus

    50plus Guest

    Messages:
    235
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Ludwig I agree with Garve, better check the output again.

    For a better way to selectively include files, follow the example of bcabank

    Garve, nice site you have :)
     
    50plus, Oct 24, 2006 IP
  11. Garve

    Garve Peon

    Messages:
    62
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Thanks 50plus!

    I don't think bcabanks solution works any better though

    <%
    page=request.querystring("page")

    if page=home then
    %>
    <!--#include file="home.asp" -->
    <% end if
    if page=contact then
    %>
    <!--#include file="contact.asp" -->
    <% end if %>

    will end up including both home.asp and contact.asp

    See http://www.asp101.com/articles/michael/dynamicincludes/default.asp for an explanation.
     
    Garve, Oct 24, 2006 IP
    ludwig likes this.
  12. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #12
    thanks, maybe this is what I needed :)

     
    ludwig, Oct 24, 2006 IP
  13. Garve

    Garve Peon

    Messages:
    62
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Sorry Ludwig - that's not going to work either - in fact it should fail completely.

    What the server will see is
    <!--#include file=-->
    because the include is carried out before the scripting.
     
    Garve, Oct 24, 2006 IP
  14. YIAM

    YIAM Notable Member

    Messages:
    2,486
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #14
    I doesn't know scripting too much, But I am using same thing here http://d.1asphos.com/dirsubmit/

    It's working nicely.
     
    YIAM, Oct 24, 2006 IP
  15. Garve

    Garve Peon

    Messages:
    62
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #15
    bcabank - sorry, couldn't get your link to work, and in the frameset code the pages seem to be .php.

    However, if you put the following at the top of home.asp (before the script delimiters)

    <p>Home Page</p>

    and this in contact.asp

    <p>Contact Page</p>

    you'll find that both of these will be printed in your HTML - no matter what request.querystring("page") is.
     
    Garve, Oct 24, 2006 IP
  16. YIAM

    YIAM Notable Member

    Messages:
    2,486
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #16
    YIAM, Oct 24, 2006 IP
  17. 50plus

    50plus Guest

    Messages:
    235
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #17
    I'm currently rebuilding a site and this works :

    Before the page html :
    productid=request.querystring("prod")

    Within the page html :
    <% If productid=293 then %>
    <!-- #include file="294.asp" -->
    <% end if %>
    <% If productid=287 then %>
    <!-- #include file="288.asp" -->
    <!-- #include file="289.asp" -->
    <% end if %>
    <% If productid=30 then %>
    <!-- #include file="29.asp" -->
    <% end if %>
     
    50plus, Oct 24, 2006 IP
  18. Garve

    Garve Peon

    Messages:
    62
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Here's the last time I'll say this - unless I misunderstand ASP completely, none of the above solutions will work.

    50plus - what you are doing is INCLUDING *ALL* the INCLUDE files into your page every time the page is loaded.

    It's possible from your numbering system that you're including hundreds of files into one page which is bound to be bad for your server. Once the files are loaded into memory, your if...then statements prevent the code you don't want from being run but it does have to be loaded into memory first.

    You might as well have your entire application written into one file instead of splitting it into separate ones.
     
    Garve, Oct 25, 2006 IP
  19. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #19
    so we came to a conclusion that all the possible ways that we are using are bad, so what is the best way to include files and not create separate pages????
     
    ludwig, Oct 25, 2006 IP
  20. Garve

    Garve Peon

    Messages:
    62
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #20
    Now that's a good question! The point of include files (I think, and I could be wrong) is that they allow you to use a piece of code in lots of different pages, but only have to update it once if you need to change it.

    So my home.asp page would have

    <!-- #INCLUDE file="header.asp" -->
    <!-- #INCLUDE file="menu.asp" -->
    Hi, This is my home page and I'd put all my home page content here
    <!-- #INCLUDE file="footer.asp" -->

    and my contact.asp page would have

    <!-- #INCLUDE file="header.asp" -->
    <!-- #INCLUDE file="menu.asp" -->
    Hi, here are my contact details.
    <!-- #INCLUDE file="footer.asp" -->

    home.asp and contact.asp would never be included into another page. This way you have individual file names for all your pages:-

    home.asp
    contact.asp

    is better for search engines than having

    index.asp?page=home.asp
    index.asp?page=contact.asp

    That way you edit your home content in home.asp, your contact details in contact.asp and the menu for both in menu.asp

    Now if you don't want to include the menu on a page, say your sitemap, then sitemap.asp would be

    <!-- #INCLUDE file="header.asp" -->
    Hi, here is my sitemap.
    <!-- #INCLUDE file="footer.asp" -->

    This way, when a viewer looks at your sitemap the server doesn't need to draw menu.asp into memory.

    However all the previous solutions do this

    <!-- #INCLUDE file="header.asp" -->
    <%
    if page <> "sitemap.asp" then
    %>
    <!-- #INCLUDE file="menu.asp" -->
    <%
    end if
    %>
    Hi, here is my sitemap.
    <!-- #INCLUDE file="footer.asp" -->

    which draws menu.asp into memory even though it doesn't get used.

    cheers

    Garve
     
    Garve, Oct 25, 2006 IP