This executes a different AFP document and subsequently resumes processing the current document.
Syntax
Server.Execute( cFile )
Parameter
cFile
You may only pass files to Server.Execute(). As the URL is processed directly by the AFP it may not include an invocation of a PHP or ASP.NET application. To execute code shared by multiple pages, you would normally specify a different AFP document in the same directory or in a subdirectory. Take for instance the return of frequently occurring elements. A further example would be the creation of tables with a higher level of complexity that are utilized in multiple pages.
If the file name of an AFP document is entered, this file name must be relative to the current document. This condition does not apply if the file can be located via the virtual AFP directory tree. This tree is defined in the <virtual> tag of afp.config. Virtual directory structures stored in a web server will be ignored as the request will not pass through the web server.
Remarks
Server.Execute() will run a request recursively. The number of potential nesting levels varies; it depends on the number of available DO calls. For AFP to run a further page, twenty execution levels must be available. This, as a rule, is equivalent to a depth of eight AFP documents.
All variables declared PRIVATE are also available in the invoked page. As session variables are usually declared PRIVATE, all data of a session is available. Variables declared LOCAL will not be available. The invocation of a page interrupts – but will not save – the current session. All session variables will be saved to the directory session after the program returns to the invoking page and successfully completes the processing of it. Although you cannot create new session variables in subordinated pages, you may modify existing ones.
Server.Execute provides a special feature for plugin developers – the Call object is again determined via CallFactory. From an invocation of a regular AFP page that is being handled by CCallAFP you may also call pages that utilize an entirely different invocation syntax like the one used for the plugin DirectCall. On the other hand, CallFactory must have the ability to process recursive invocations. If for optimization purposes you keep a Call object in store at all times you will have to create a new object at every recursive invocation, and you will not be able to re-use the first instance.
You cannot pass parameters to Server.Execute(). On the one hand, this means that all parameters passed to the calling page are also available in the called page. On the other hand, this means that you cannot call a second page with a parameter. To pass parameters you could consider the following alternative:
<%
LOCAL lcQueryString
lcQueryString = Request.cQueryString
Request.cQueryString = "par1=Value1&"+"par2=Value2"
Request.ResetQueryString()
Server.Execute("page2.afp")
Request.cQueryString = m.lcQueryString
Request.ResetQueryString()
%>
In page2.afp you can now access all parameters as usual using Request.QueryString("par1").
Example
main.afp
<HTML>
<HEAD>
<TITLE>Server.Execute()</TITLE>
<HEAD>
<BODY>
<% Server.Execute("menu.afp") %>
<BODY>
<HTML>
menu.afp
<A HREF="<% ? Session.Url("index.afp") %>">home</a> |
<A HREF=http://www.afpages.de target="_blank">www.afpages.de</> |
See also
Response.Call() | Response.Redirect() | Server.Level() | Server.Transfer()