...

View Full Version : Can i pass arguments in include?



jaywhy13
01-09-2005, 10:00 PM
I used the include statement.... it worked fine

Fine, until I tried to pass queryString arguments into the include syntax it tells me that they cannot find that page. The asp file has no HTML in it, its just a sequence of code that is used on different pages.... But i think there must be a simple reason I must be overlooking


Please help

glenngv
01-10-2005, 02:30 AM
Use Server.Execute (http://www.4guysfromrolla.com/webtech/042602-1.shtml).

The Path argument of that method cannot include a query string, however, any query string that was available to the calling ASP page will be available to the called ASP page.

jaywhy13
01-10-2005, 03:29 AM
B E A UTIFUL!!!!!

Thanks alot man!!! :thumbsup:

ghell
01-10-2005, 04:04 PM
#include, server.execute() and server.transfer() all keep the page state, ie variables are transfered, although this is done in a different way

#include is pretty much just loading the code into the original page, then processing it all at once. this means that relative items (such as other includes) need to be relative to the main page that it is being called from..there are other differences too but this is the only one i've really noticed

server.execute() and server.transfer() both transfer the state and run the page separately (server.execute() then transfers the page back again, server.transfer() doesnt) this means that relatives to these pages are relative to the file it is executing, not the file that is calling it (which is useful if you want to make your code available from more than one page

note: server.execute() and server.transfer() are only available after asp3 but a lot of people think dynamic includes are totally impossible in ASP

as QueryStrings are just variables in a collection, these are transfered from the main page with the rest of the page state

one thing that confuses me is that if i have a page that includes a file with common functions in it, then execute to another page, the page being executed cant use the functions that were included from the calling page, ie this:

functions.asp:
<%
addThese(intNum1, intNum2)
addThese = intNum1 + intNum2
End Function
%>
default.asp:
<!--#include file="functions.asp" -->
<%
Response.Write addThese(2, 2)
strWelcome = "hello"
Server.Execute("pages/home.asp")
%>

pages/home.asp:
<!--#include file="../functions.asp" --><%'This line is needed for this page to be able to call a function, im not sure if server.execute("functions.asp") is any different if it is used on default.asp
Response.Write strWelcome 'however, this is still here from before
Response.Write addThese(3, 3)
%>

gwendaal
01-10-2005, 05:42 PM
you can also use a very heavy code

Select case QueryString
Case 1 %>
include file 1
<%Case 2%>
include file 2

it is horrible but it works

jaywhy13
01-10-2005, 06:17 PM
thanks all for your help!!!! :thumbsup:
Here's what worked for me tho....
I needed the code in the include to know what page I was on, so what I did was to define a variable right before puttin in the include:
thepage="whatever.asp" and that basically solved my problem.
It really helped to kno that the include statement includes the code and processes it all at once.... thanks!

Thanks alot.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum