HomeASP HostingWeb DesignRegister DomainSupportAbout Us

FAQ
Support :: FAQ


How to use Server.Execute method in ASP
The Server.Execute method is a new ASP method, introduced with IIS 5.0 for a first time. You can execute a child ASP page with the Server.Execute and treat the child ASP page as part of the main page.

What are the advantages of using Server.Execute, why did Microsoft introduce a new method?

The main advantage of using Server.Execute is that you can do a dynamic conditional execution of an ASP pages. For example with the SSI includes you include file like this:

<-- #include File = "c:\Inetpub\wwwroot\Your_App\include1.asp" -->

<-- #include Virtual = " /Your_App/include1.asp" -->

One problem with the #include command that it is processed before the page is executed, while the Server.Execute method can be used after the ASP page processing has started. The developers can conditionally execute ASP pages depending the main page business logic or on the user input with Server.Execute method.

You can find an example of Server.Execute in action bellow.

Open any text editor, copy and paste the code below in it and save the file as Main.asp to a web folder:

<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Server.Execute Method in Action</title>
</head>
<body>
<% If Request.QueryString("file")="" Then %>
This is the main page!<br><br>
<a href="main.asp?file=file1.asp">Execute File1.asp</a> |
<a href="main.asp?file=file2.asp">Execute File2.asp</a>
<% Else %>
<a href="main.asp">Back</a>
<% Server.Execute Request.QueryString("file") %>
<% End If %>
</body>
</html>


The File1.asp looks like this:

<%@LANGUAGE="VBSCRIPT"% >
<% Response.Write "This is File1" % >


The File2.asp looks like this:

<%@LANGUAGE="VBSCRIPT"%>
<% Response.Write "This is File2, which has longer text :)" %>


After you have saved all 3 ASP pages in your web folder, open a new browser and load the main.asp:

http://localhost/Your_Web_Folder/Main.asp

Now you can click on the File1 and File2 links to trigger the Server.Execute method.
© Copyright 2001-2004 Art Branch Inc.