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 <!--#include file="home.asp" --> Can anyone tell me how to do it?
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.
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.
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.
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 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
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.
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.
I doesn't know scripting too much, But I am using same thing here http://d.1asphos.com/dirsubmit/ It's working nicely.
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.
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 %>
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.
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????
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