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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include problems

Status
Not open for further replies.

rastkocvetkovic

Programmer
Aug 11, 2002
63
0
0
SI
Is there a possibility to decide which web_page.asp to include based on a variable. Because in my example, the thing doesn't work at all. Please help me, I'm in a hurry.

Problem (Variable Content is previosly set):

<%
If Content = &quot;clanki_upravljanje_clankov&quot; Then
%>
<!--#include file=&quot;_clanki_upravljanje_clankov.asp&quot; -->

<%
ElseIf Content = &quot;clanki_vnesi_nov_clanek&quot; Then
%>
<!--#include file=&quot;_clanki_vnesi_nov_clanek.asp&quot; -->

<%
ElseIf Content = &quot;kategorije_pregled_clankov&quot; Then
%>
<!--#include file=&quot;_kategorije_pregled_clankov.asp&quot; -->

<%
Else
%>
<!--#include file=&quot;_prva_stran.asp&quot; -->
<%
End If
%>
 
rastkocvetkovic,

ASP pages work a bit differently then how you're trying to use them...

The first thing the asp engine does when processing a page is look for include files. Since you can put them anywhere in your document, it'll scan the whole document before processing any part of it. It looks for the pound sign &quot;#&quot; and then includes any pages declared. After that, it starts processing the code. So your page might as well have been written like this to get the exact same results:

*******************************************************

<!--#include file=&quot;_clanki_upravljanje_clankov.asp&quot; -->
<!--#include file=&quot;_clanki_vnesi_nov_clanek.asp&quot; -->
<!--#include file=&quot;_kategorije_pregled_clankov.asp&quot; -->
<!--#include file=&quot;_prva_stran.asp&quot; -->
<%
If Content = &quot;clanki_upravljanje_clankov&quot; Then

ElseIf Content = &quot;clanki_vnesi_nov_clanek&quot; Then

ElseIf Content = &quot;kategorije_pregled_clankov&quot; Then

Else

End If
%>

******************************************************

Now there is somthing you can do to include files without actually including them. It won't work exactly like how you wanted this too, however it should proove usefull if you are actually on an IIS server rather than a PWS machine.

You can use: Server.Transfer(somePage.asp)
Or you can use: Server.Execute(somePage.asp)

for transfer it'll work similar to response.redirect except I believe for this it'll carry everything from your current page to the new one. (I could be wrong on that though).

for Execute, it'll go to the specified page, execute the code on it and return to the current one. Again, I'm not positive, but I think it may work like an include where it'll take the data from that page and use it in your current one. It should carry the info back to the originating page. You have to try it to be sure though.

so you could type somthing like this:

********************************************************

<%
If Content = &quot;clanki_upravljanje_clankov&quot; Then
Server.Execute(&quot;_clanki_upravljanje_clankov.asp&quot;)

ElseIf Content = &quot;clanki_vnesi_nov_clanek&quot; Then
Server.Execute(&quot;_clanki_vnesi_nov_clanek.asp&quot;)

ElseIf Content = &quot;kategorije_pregled_clankov&quot; Then
Server.Execute(&quot;_kategorije_pregled_clankov.asp&quot;)

Else
Server.Execute(&quot;_prva_stran.asp&quot;)

End If
%>

*********************************************************

If this isn't exactly it, you might have to mess around with it just a little. Like removing or adding quotes around the actual page name within the parenthesis and such. But I think this is right.

Hope this helps.
-Ovatvvon :-Q
 
Thank you very much, Ovatvvon, for your answer. I'll try what you've said and I'll write back what I found out. I think it is a useful piece of information for any ASP developer.
 
Your example should work cause I did something like that before. Tell me more about how you acquire the value of the &quot;Content&quot; variable. And try sometimes to use a SELECT CASE structure. It's easier to read and to debug.

asiby
siby@abdoulaye.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top