It is possible to pass a parameter through server.execute
?
Fx. I have in my site.asp
an IF-scenario where I need functions.asp?a=something&id=123
executed. Is this possible?!
On site.asp:
dim id
id = 123
if b = "hi" then
server.execute("functions.asp?a=something&id=" & id)
else
response.write("No way dude")
end if
On functions.asp
a = request.querystring("a")
id = request.querystring("id")
if a = "something" and cint(id) > 100 then
response.write("Yes way dude")
else
response.write("No way dude")
end if
Why not to use
#include
instead ofserver.execute
?I looked for a difference and found that in this particular case, using
#include
is the best solution: https://en.wikibooks.org/wiki/Active_Server_Pages/Server-Side_Includes#What_it_DoesYou need some variables defined in parent page to be used in child, so your solution could be:
On functions.asp
Advantages:
This question may be old and resolved, but the best answer doesn't mention everything, and there is information clearly posted on Microsoft.com about it:
Server.Execute Method
The following collections and properties are available to the executed ASP page:
So as you can see, there are 5 ways Microsoft suggests to pass variables through to a
Server.Execute
method. Before I saw this on Microsoft, the preferred method wasSession
, as the best answer suggests, since I saw this before the info on Microsoft.com. But after noticing thatQueryStrings
can be passed from the previous page, I would have to say this beats usingSession
for passing values.Session
would be needed if your application required you adding variables to the executing page.But passing variables, I would say
QueryStrings
, and it's easy to apply if your application allows the flexibility. I'm sure you know how to already use querystrings, but in the sense of using it for aServer.Execute
method, you can simply do this:Consider having
ASP1.asp
andASP2.asp
:ASP1.asp includes:
ASP2.asp includes:
When you call
ASP1.asp?id=123
You will notice that ASP2.asp also see's the sameQuerystring
passed to ASP1.asp, so it would write123
on the response of ASP1.asp.That's much less complicated than using a
Session
for the task.You can't use querystring in
Server.Execute
, it's clearly mentioned in the official documentation.What you can do is much better: you can directly access the variableid
defined insite.asp
insidefunctions.asp
, and you can also declare and set another variable,a
:--site.asp:
--functions.asp
As it creates whole new "scripting environment" the executed file won't have access to the calling code properties, methods or variables, only to the global Request parameters, Session etc.
With this in mind, I fear the most simple way around is using Session variable to pass the value between pages:
And then:
In short: YES, you can use QueryString values in conjunction with Server.Execute within an ASP.NET page or application.
You can pass dynamic variables in a QueryString argument assembled in the executing ASPX page (page1.aspx), as follows:
In this example, page2.aspx can then reference and use the following values: