Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

True Dynamic Includes using SELECT CASE 4

Status
Not open for further replies.

talon121a

MIS
Aug 21, 2003
92
US
This is an easy way to do true dynamic SSI includes.

<%

'My sample, customize this any way ya want..
'

Select Case Request.QueryString(&quot;page&quot;)

Case &quot;history&quot;:
%> <!--#INCLUDE FILE=&quot;history.asp&quot;-->
<%
Case &quot;testing&quot;:
%> <!--#INCLUDE FILE=&quot;testing.asp&quot;-->
<%
Case Else:
%> <!--#INCLUDE FILE=&quot;mainsite.asp&quot;-->
<%
End Select

' I hope this was worth my posting! :)
I know once I decided to do this, it's made every page I've developed easier to make.
%>
 
That's a good idea,

careful though, it could create some enourmous/slow pages.
The server will include each include file every time and parse each one as well if it is a .ASP page. Then it will only output the one that was selected.


Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
Just to touch on that visually a bit that tlhawkins mentioned.
in essence if you do this with the includes holding the following
history.asp holds
<%
response.write &quot;this is the history page
%>

testing.asp holds
<%
response.write &quot;this is the testing page
%>

mainsite.asp holds
<%
response.write &quot;this is the mainsite page
%>

then you actually do this instead of reading the include file

<%
Select Case Request.QueryString(&quot;page&quot;)
Case &quot;history&quot;:
%>
<%
response.write &quot;this is the history page
%>
<%
Case &quot;testing&quot;:
%>
<%
response.write &quot;this is the testing page
%>
<%
Case Else:
%>
<%
response.write &quot;this is the mainsite page
%>
<%
End Select
%>

in all though unless the files are large the load should not be effected greatly. upon them
gaining in size though I would execute them instead.
another thing to cnsider is that open/close of the ASP taging.
It's been discussed that this is not a concern as it is so little of a performance hit,
however if there are many in and out along with (don't quote me on how this portion is read
<%
response.write &quot;this is the mainsite page
%>
as open/close again, then you have a few in there and this may be where that will take a effect on the
page.

Again, there is no need to worry and this is efficient in coding a maintenance up to the point
the files get large enough to be noticable in load and or function call needs.

Good tip talon121a I'm glad to have the reference now as this
comes up far to often.

_____________________________________________________________________
onpnt2.gif
[sub]
Hakuna matata!!
[/sub]
 
Mmmmm....
There is a better way:

Code:
<%
   Select Case Request.QueryString(&quot;page&quot;)
     Case &quot;history&quot;:
        Server.Execute &quot;history.asp&quot;
     Case &quot;testing&quot;:
        Server.Execute &quot;testing.asp&quot;
     Case Else
        Server.Execute &quot;mainsite.asp&quot;
    End Select
%>

This will only cause one file to be executed (parsed and verified) rather than every .ASP in the site.





Roger J Coult
Allied Laboratory Services Limited
Grimsby, UK
 
Even nicer. Using the Execute statement.. will definitely make things faster.

I guess I sorta gave a baseline. I know alot of people that commonly ask me this type of setup. And 'how to' advice.. This is just one I had to get off my chest :)

Thanks for the great comments guys!

I'll try to keep adding :)

Jason
 
You could also use the following:
Code:
<%  
   Server.Execute(Request.QueryString(&quot;page&quot;) & &quot;.asp&quot;)
%>
João.
 
nice... Thanks for posting the question!

I did a search of the FAQs in the ASP section and found this: faq333-4118

Earnie Eng
 
woja is right... Select Case using the server.execute is way faster.
 
Why use Case when you can achieve the same result with just one line of code?
Am I missing something?

João.
 
HoppingMadRabbit,

Your post using Request.QueryString(&quot;page&quot;) and executing anypage.asp .. that could be construed as a security breach.. I personally wouldnt choose that method.. But.. Server.Execute is a good way of doing it, considering it speeds up the ASP logic. Rather than switching the ASP engine from processing ASP then HTML then ASP, etc.

Thanks!

Jason
 
talon121a,
it is indeed more secure, I took the case else condition for just another regular case condition, my mistake... should have looked closer, sorry, I agree with you. Also it does speed up the logic not having to switch from ASP to HTML.

One other method to consider is using Server.Transfer() instead of Server.Execute(). Almost the same thing however after processing the &quot;included&quot; file it doesn't switch back to the original page but rather stays and stops at the end of the included file.

Usefull if there is not any remaining code in main page. It may also speed up things a little, I believe.

João.
 
Better way it's using Server.Transfer instead of Server.Execute.
I dont think that you read the documentation lately about Server.Transfer, it works as it should on IIS5.0+

________
George, M
 
Wow I'm really impressed with the amount of input I've been receiving with this, its changed the way Ive programmed ASP sites from now on. ;-)

I thank you all ;-)

Jason
 
Why not use response.redirect instead of include?

Just a question.
 
You will lose eventualy Response.Form or RequestString values, using Server.Transfer will keep those to all the pages you transfer till the first Response.end

________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top